PDA

View Full Version : openGL and showing stuff

nolfolk
03-12-2009, 11:23 PM
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(){
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);

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

glutSwapBuffers();
glutPostRedisplay();
}

int main(){
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 400);
glutCreateWindow("Teste Viewports");
glutDisplayFunc(Desenha);
glutMainLoop();

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...

screenSize(500,400);
goto(10,10);
drawRetangle(10,10);

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 :(

Thanks.

taytay
03-12-2009, 11:54 PM
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

nolfolk
03-13-2009, 10:01 AM
~ Solved ~
Thank You :D Now I can understand :D :D