openGL and showing stuff

Hi folks, how are you ?

Ok, I already made a Snake game in openGL and all, it was just to see if i could really do something, the code was all-messed-up, I just taked the functions that I needed and did everything without “thinking”…

Now I’m REALLY starting to learn openGL, and here’s my first problem: I can’t understand the View Stuff, I mean… look my code:

#include <gl/glut.h>

void Desenha(){

     glColor3f(1, 0, 0.0f);
           glVertex2i(0, 10);
           glVertex2i(0, 0);
           glVertex2i(10, 0);
           glVertex2i(10, 10);

int main(){
     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
     glutInitWindowSize(500, 400);
     glutCreateWindow("Teste Viewports");
     return 0;

Simple, right ? It was a Screen with 500x400px, where I drawn a square in “10, 10 position”, right ? NO! for some reason the square appears giantly at 1/4 of the screen … I just want to know the size of things, you know ? It would be nice if I understand something like…


And with that he creates a 500x400px screen where in 10px to X and 10px to Y he draws a retangle with 10x10px, you know ?

Do someone have any tutorial to understand that ? I have a openGL book here, but it doesn’t help with that :frowning:


You need to specify gluOrtho2D function

gluOrtho2D(0.0, 500.0, 0.0, 400.0);

Define this after creating the window in main.

First arg is left most pixel, second is right third one is bottom and the last one is top.

So bottom-left will be 0,0 and top-right will be 500-400

In your code square covers the 1/4 of screen beceause in the begining gluOrtho2D is defined as -1.0, 1.0, -1.0, 1.0

~ Solved ~
Thank You :smiley: Now I can understand :smiley: :smiley: