Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL Change Window Drawing Size

Started by glu Mar 31, 2013 at 4:06 PM 1 replies 1.9k views
Original Post
glu
glu
Hey, I have no clue why this is such a huge problem, it should be extremely easy to fix, but I've spent hours looking on how to simply change the window from 0, 0 being the center and 1, 1 being the max to whatever I want, or in this case, the window width, and height. I have tried using glOrtho, and gluOrtho2D, but when I do, I get a black screen, nothing works.


This code SHOULD draw a perfect line across the screen, but doesn't do anything


gluOrtho2D(0, 800, 600, 0); //This is the code messing up, when I remove it, I get an imperfect line, but a line none the less.

glBegin(GL_LINE_STRIP);
glVertex2i(0, 0);
glVertex2i(800, 600);
glEnd();
21st Century Moose
21st Century Moose

It sounds like you're forgetting to call glLoadIdentity before your gluOrtho2D. Also make sure that you've got glMatrixMode (GL_PROJECTION) before both, and also identity in modelview. Full code:


glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0, 800, 600, 0);

glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();

This is needed because gluOrtho2D is documented as being equivalent to glOrtho with near -1 and far 1, and glOrtho multiples the current matrix by the generated ortho matrix; it doesn't replace it.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
glu
glu
 

It sounds like you're forgetting to call glLoadIdentity before your gluOrtho2D.  Also make sure that you've got glMatrixMode (GL_PROJECTION) before both, and also identity in modelview.  Full code:
 

glMatrixMode (GL_PROJECTION);glLoadIdentity ();gluOrtho2D (0, 800, 600, 0);glMatrixMode (GL_MODELVIEW);glLoadIdentity ();
 
This is needed because gluOrtho2D is documented as being equivalent to glOrtho with near -1 and far 1, and glOrtho multiples the current matrix by the generated ortho matrix; it doesn't replace it.
 

Wow, THANK YOU. I have actually posted this same thread twice on stackoverflow, and once on the OpenGL discussion boards, and no one has replied with anything useful. Thanks, your the first person to actually help me with this, and it works with no problems now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.