# Source CodeDrawing In OpenGL

#### Solaire

##### Respected Hacker
Dank Tier VIP
Update do these videos:

I thought I'd post how to draw in OpenGL since I recently learned. It's really easy once you get it down, and can be really fun! This tutorial assumes you have a wrapper or hook.

Let's start with simply drawing a dot. Why's that useful, you ask? Radars, circles, whatever your mind imagines, you've got it!

C++:
``````// This is the size of our point.
glPointSize(4);
// This is the color of our point, and in this case it's red
glColor3f(1.0f, 0.0f, 0.0f);

//This is where our drawing starts. We are using GL_POINTS since we want to draw
//... well, Points!
glBegin(GL_POINTS);
// This is the position that we draw the point at.
//Just a quick note, x increases towards the right, and decreases to the left
//Y increases the further down you go, and decreases the further up you go
glVertex2f(DrawX, DrawY);
//End our drawing
glEnd();``````
Pretty simple

Now, for drawing a line, we replace GL_POINTS with GL_LINES.

C++:
``````//This sets the lines width when drawing
glLineWidth(1.0);

//Start drawing our lines
glBegin(GL_LINES);
//These will create a simple Plus symbol
glVertex2f(110, 10);
glVertex2f(110, 210);

glVertex2f(10,110);
glVertex2f(210, 110);
glEnd();``````
We have lines, and we have dots. How do we draw shapes??

EASILY!!

C++:
``````glBegin(GL_POLYGON);
glVertex2f(10, 10);
glVertex2f(210, 10);
glVertex2f(210, 210);
glVertex2f(10, 210);
glEnd();``````
This draws a simple box. For better understanding, look up these functions, as they're all very well documented. If you combine all of these, you can create a radar! Here's a simple start for the radar. You just have to draw the entity dots yourself:

C++:
``````const float InnerEdge = 10;
const float Center = 110;
const float OuterEdge = 210;

glPointSize(4);
glColor3f(1.0f, 0.0f, 0.0f);

//Draw the dot in the center (Our player)
glBegin(GL_POINTS);
glVertex2f(Center, Center);
glEnd();

glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(1.0);

//Draw the Plus symbol (Mostly for looks and orientation)
glBegin(GL_LINES);
glVertex2f(Center, InnerEdge);
glVertex2f(Center, OuterEdge);

glVertex2f(InnerEdge, Center);
glVertex2f(OuterEdge, Center);
glEnd();

glColor3f(0.2f, 0.2f, 0.2f);

//Draw the radar box
glBegin(GL_POLYGON);
glVertex2f(InnerEdge, InnerEdge);
glVertex2f(OuterEdge, InnerEdge);
glVertex2f(OuterEdge, OuterEdge);
glVertex2f(InnerEdge, OuterEdge);
glEnd();``````
Just a quick note, when drawing in OpenGL, the first thing you draw is on top (The dot), and the last thing you draw is on the bottom (The radar box).

Happy hacking,
Krampus

Last edited by a moderator:

#### c5

##### Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Sweet, you don't need a wrapper however, just hook wglSwapBuffers for example.

#### Rake

##### Cesspool Admin
Administrator
Very cool Krampus hella nice work!

#### Solaire

##### Respected Hacker
Dank Tier VIP
Sweet, you don't need a wrapper however, just hook wglSwapBuffers for example.
Updated the beginning, thanks

Very cool Krampus hella nice work!
Thanks

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.