Solved Draw box, text

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
Wow thanks for the fast help. But how can i draw rects? I tried this code but it doesnt work.

C++:
void DrawBox(float x, float y, float w, float h)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 700, 700, 0, -10, 10);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix();
    glTranslatef(x, y, 0);                          
    glBegin(GL_QUADS);
    glColor3f(1, 0, 0);
    glVertex2f(0, 0);
    glVertex2f(0, h);
    glVertex2f(w, h);
    glVertex2f(w, 0);
    glEnd();
    glPopMatrix();
}
C++:
void Draw::box(GLfloat x, GLfloat y, GLfloat xLen, GLfloat yLen, GLfloat r, GLfloat g, GLfloat b)
{
    //Set our attributes
    glColor3f(r, g, b);

    //Draw our box
    glBegin(GL_QUADS);
    glVertex2f(x, y);
    glVertex2f(x + xLen, y);
    glVertex2f(x + xLen, y + yLen);
    glVertex2f(x, y + yLen);
    glEnd();
}
It's a different process for modern OpenGL. For that, go here https://www.learnopengl.com/
 

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
GLUT can help you with that. There are several free libraries you can use for text rendering as well.
C++:
    //Draws a string onto the screen. Font is a font (ex: GLUT_BITMAP_HELVETICA_18). Use the end of the funct like printf
    void string(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, void * font, char const*const pFmtText, ...);
C++:
void Draw::string(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, void * font, char const*const pFmtText, ...)
{
    int newLineDist;

    //Set the distance dynamically for new lines
    switch ((int)font)
    {
    case (int)GLUT_BITMAP_9_BY_15:
        newLineDist = 16;
        break;

    case (int)GLUT_BITMAP_8_BY_13:
        newLineDist = 14;
        break;

    case (int)GLUT_BITMAP_TIMES_ROMAN_10:
        newLineDist = 11;
        break;

    case (int)GLUT_BITMAP_TIMES_ROMAN_24:
        newLineDist = 25;
        break;

    case (int)GLUT_BITMAP_HELVETICA_10:
        newLineDist = 11;
        break;

    case (int)GLUT_BITMAP_HELVETICA_12:
        newLineDist = 13;
        break;

    case (int)GLUT_BITMAP_HELVETICA_18:
        newLineDist = 19;
        break;

    default:
        newLineDist = 19;
        break;
    }

    //Set our attributes
    glColor3f(r, g, b);
    glRasterPos2i(x, y);

    //Allocate memory for a temporary result string. You could probably do much less
    char *const pTemp = new char[5000];

    //Put all of the text into pTemp
    va_list vaList;
    va_start(vaList, pFmtText);
    int const TextLen = vsprintf(pTemp, pFmtText, vaList);
    va_end(vaList);

    //Draw the string
    for (unsigned int Counter = 0; Counter < TextLen; ++Counter)
    {
        if (pTemp[Counter] == '\n')
        {
            y += newLineDist;
            glRasterPos2i(x, y);
            continue;
        }

        glutBitmapCharacter(font, pTemp[Counter]);
    }

    //Prevent memory leaks
    delete[] pTemp;
}
Taken directly from my OpenGL drawing class. All of the knowledge is fairly common, so credits to plenty of people (I forget who specifically). You can tweak the newline distances to your liking, or remove it altogether.
 

dromenox

Newbie
May 3, 2014
6
122
0
GLUT can help you with that. There are several free libraries you can use for text rendering as well.
C++:
    //Draws a string onto the screen. Font is a font (ex: GLUT_BITMAP_HELVETICA_18). Use the end of the funct like printf
    void string(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, void * font, char const*const pFmtText, ...);
C++:
void Draw::string(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, void * font, char const*const pFmtText, ...)
{
    int newLineDist;

    //Set the distance dynamically for new lines
    switch ((int)font)
    {
    case (int)GLUT_BITMAP_9_BY_15:
        newLineDist = 16;
        break;

    case (int)GLUT_BITMAP_8_BY_13:
        newLineDist = 14;
        break;

    case (int)GLUT_BITMAP_TIMES_ROMAN_10:
        newLineDist = 11;
        break;

    case (int)GLUT_BITMAP_TIMES_ROMAN_24:
        newLineDist = 25;
        break;

    case (int)GLUT_BITMAP_HELVETICA_10:
        newLineDist = 11;
        break;

    case (int)GLUT_BITMAP_HELVETICA_12:
        newLineDist = 13;
        break;

    case (int)GLUT_BITMAP_HELVETICA_18:
        newLineDist = 19;
        break;

    default:
        newLineDist = 19;
        break;
    }

    //Set our attributes
    glColor3f(r, g, b);
    glRasterPos2i(x, y);

    //Allocate memory for a temporary result string. You could probably do much less
    char *const pTemp = new char[5000];

    //Put all of the text into pTemp
    va_list vaList;
    va_start(vaList, pFmtText);
    int const TextLen = vsprintf(pTemp, pFmtText, vaList);
    va_end(vaList);

    //Draw the string
    for (unsigned int Counter = 0; Counter < TextLen; ++Counter)
    {
        if (pTemp[Counter] == '\n')
        {
            y += newLineDist;
            glRasterPos2i(x, y);
            continue;
        }

        glutBitmapCharacter(font, pTemp[Counter]);
    }

    //Prevent memory leaks
    delete[] pTemp;
}
Taken directly from my OpenGL drawing class. All of the knowledge is fairly common, so credits to plenty of people (I forget who specifically). You can tweak the newline distances to your liking, or remove it altogether.
Wow thanks for the fast help. But how can i draw rects? I tried this code but it doesnt work.

C++:
void DrawBox(float x, float y, float w, float h)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 700, 700, 0, -10, 10);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix();
    glTranslatef(x, y, 0);                          
    glBegin(GL_QUADS);
    glColor3f(1, 0, 0);
    glVertex2f(0, 0);
    glVertex2f(0, h);
    glVertex2f(w, h);
    glVertex2f(w, 0);
    glEnd();
    glPopMatrix();
}
 

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
Thanks! The box function works perfectly! But when i try to render the text the game closes.
Not sure what would cause that. Maybe the game doesn't use GLUT? I've never run into that issue, see if there are any GetLastError functions you could possibly intercept or call yourself to find out what the issue is, or try and set a BP and trace into the function to see what could cause the issue.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,118
78,998
2,392
I has crashing problems with freeglut and openglut when using glutBitmapCharacter, but the original GLUT works 100% no problem
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
Old opengl font class from i dont know what century.

C++:
#pragma once

#include <Windows.h>
#include <gl\GL.h>
#include <stdio.h>

class Font
{
private:
	HDC				hDC;
	HFONT			hOldFont;				
	HFONT			hFont;
	UINT			FontBase, FontBaseUnderline, FontBaseBig;
	bool            bFontsBuild;

public:
	Font::Font() { bFontsBuild = 0; };
	void BuildFonts();
	void glPrint(int x, int y, int r, int g, int b, const char *fmt, ...);
	void glPrintUnderline(int x, int y, const char *fmt, ...);
	void glPrintBig(int x, int y, int r, int g, int b, const char *fmt, ...);
};
C++:
#include "Font.h"

unsigned int ColorMap(int a, int r, int g, int b) 
{
    return ((UINT32)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff)));
}

void Font::BuildFonts()
{
	hDC			= wglGetCurrentDC();
 
	FontBase	= glGenLists(96);
	hFont		= CreateFontA(-12, 0, 0, 0, FW_NORMAL,	FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); //"Lucida Console");					
	hOldFont	= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBase);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);	
 
	FontBaseUnderline = glGenLists(96);
	hFont			= CreateFontA(-10, 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); 					
	hOldFont		= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBaseUnderline);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);
 
	FontBaseBig		= glGenLists(96);
	hFont			= CreateFontA(-14, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); 					
	hOldFont		= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBaseBig);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);
 
	bFontsBuild = true;
}
 
void Font::glPrint(int x, int y, int r, int g, int b, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();
 
	if (fmt == NULL)	return;	
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glRasterPos2i(x,y);
 
	char		text[256];								
	va_list		ap;	
 
	va_start(ap, fmt);									
	vsprintf_s<256>(text, fmt, ap);						
	va_end(ap);		
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPushAttrib(GL_LIST_BIT);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glListBase(FontBase - 32);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPopAttrib();	

	glColor3f( 1, 1, 1 );
}
 
void Font::glPrintUnderline(int x, int y, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();
 
	if (fmt == NULL)	return;	
 
	glRasterPos2i(x,y);
 
	char		text[256];								
	va_list		ap;	
 
	va_start(ap, fmt);									
	vsprintf_s<256>(text, fmt, ap);						
	va_end(ap);		
 
	glPushAttrib(GL_LIST_BIT);							
	glListBase(FontBaseUnderline - 32);								
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	
	glPopAttrib();										
}
  
void Font::glPrintBig(int x, int y, int r, int g, int b, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();	
 
	if (fmt == NULL)	return;
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glRasterPos2i(x,y);
 
	char		text[256];								
	va_list		ap;	
 
	va_start(ap, fmt);
    vsprintf_s<256>(text, fmt, ap);
	va_end(ap);
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPushAttrib(GL_LIST_BIT);
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);						
	glListBase(FontBaseBig - 32);		
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);			
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPopAttrib();		

	glColor3f( 1, 1, 1 );
}
 

dromenox

Newbie
May 3, 2014
6
122
0
Old opengl font class from i dont know what century.

C++:
#pragma once

#include <Windows.h>
#include <gl\GL.h>
#include <stdio.h>

class Font
{
private:
	HDC				hDC;
	HFONT			hOldFont;				
	HFONT			hFont;
	UINT			FontBase, FontBaseUnderline, FontBaseBig;
	bool            bFontsBuild;

public:
	Font::Font() { bFontsBuild = 0; };
	void BuildFonts();
	void glPrint(int x, int y, int r, int g, int b, const char *fmt, ...);
	void glPrintUnderline(int x, int y, const char *fmt, ...);
	void glPrintBig(int x, int y, int r, int g, int b, const char *fmt, ...);
};
C++:
#include "Font.h"

unsigned int ColorMap(int a, int r, int g, int b) 
{
    return ((UINT32)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff)));
}

void Font::BuildFonts()
{
	hDC			= wglGetCurrentDC();
 
	FontBase	= glGenLists(96);
	hFont		= CreateFontA(-12, 0, 0, 0, FW_NORMAL,	FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); //"Lucida Console");					
	hOldFont	= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBase);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);	
 
	FontBaseUnderline = glGenLists(96);
	hFont			= CreateFontA(-10, 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); 					
	hOldFont		= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBaseUnderline);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);
 
	FontBaseBig		= glGenLists(96);
	hFont			= CreateFontA(-14, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier"); 					
	hOldFont		= (HFONT) SelectObject(hDC, hFont);           
	wglUseFontBitmaps(hDC, 32, 96, FontBaseBig);				
	SelectObject(hDC, hOldFont);							
	DeleteObject(hFont);
 
	bFontsBuild = true;
}
 
void Font::glPrint(int x, int y, int r, int g, int b, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();
 
	if (fmt == NULL)	return;	
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glRasterPos2i(x,y);
 
	char		text[256];								
	va_list		ap;	
 
	va_start(ap, fmt);									
	vsprintf_s<256>(text, fmt, ap);						
	va_end(ap);		
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPushAttrib(GL_LIST_BIT);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glListBase(FontBase - 32);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPopAttrib();	

	glColor3f( 1, 1, 1 );
}
 
void Font::glPrintUnderline(int x, int y, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();
 
	if (fmt == NULL)	return;	
 
	glRasterPos2i(x,y);
 
	char		text[256];								
	va_list		ap;	
 
	va_start(ap, fmt);									
	vsprintf_s<256>(text, fmt, ap);						
	va_end(ap);		
 
	glPushAttrib(GL_LIST_BIT);							
	glListBase(FontBaseUnderline - 32);								
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	
	glPopAttrib();										
}
  
void Font::glPrintBig(int x, int y, int r, int g, int b, const char *fmt, ...)					
{
	if (!bFontsBuild) BuildFonts();	
 
	if (fmt == NULL)	return;
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glRasterPos2i(x,y);
 
	char		text[256];								
	va_list		ap;	
 
	va_start(ap, fmt);
    vsprintf_s<256>(text, fmt, ap);
	va_end(ap);
 
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPushAttrib(GL_LIST_BIT);
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);						
	glListBase(FontBaseBig - 32);		
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);			
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	
	glColor3f(static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f);		
	glPopAttrib();		

	glColor3f( 1, 1, 1 );
}
Thanks for the help, your code works. But look at my code: If i uncomment this line the rectangle overlaps the text. Is this normal?
Sorry for my english if there is any error, i am learning :)



C++:
void Hack::HackMain()
{
	//draw->DrawRect(100, 100, 400, 200, 128, 128, 45, 255);
	font->glPrint(150, 110, 0, 0, 0, "hahaha");

}

Edit: This works

C++:
	font->glPrint(150, 110, 0, 0, 0, "hahaha");
	draw->DrawRect(100, 100, 400, 200, 128, 128, 45, 255);
 

Obsta

Jr.Hacker
Meme Tier VIP
Jan 27, 2014
394
2,978
17
Thanks for the help, your code works. But look at my code: If i uncomment this line the rectangle overlaps the text. Is this normal?
Sorry for my english if there is any error, i am learning :)



C++:
void Hack::HackMain()
{
	//draw->DrawRect(100, 100, 400, 200, 128, 128, 45, 255);
	font->glPrint(150, 110, 0, 0, 0, "hahaha");

}

Edit: This works

C++:
	font->glPrint(150, 110, 0, 0, 0, "hahaha");
	draw->DrawRect(100, 100, 400, 200, 128, 128, 45, 255);
Think about it, you're drawing objects to a buffer, they get laid on top of each other. The order you draw them is the order they get placed on top of each other.
 

dromenox

Newbie
May 3, 2014
6
122
0
Think about it, you're drawing objects to a buffer, they get laid on top of each other. The order you draw them is the order they get placed on top of each other.
Exactly. But why if I draw the text after the rectangle is the rectangle on top of it?
 

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
Exactly. But why if I draw the text after the rectangle is the rectangle on top of it?
My guess would be that the buffer follows the rules of first in last out. To go further, the first thing put into the buffer will be the last thing drawn, making it go over everything else.

Someone please correct me if I phrased anything wrong. I'm very tired atm :L
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods