Jump to content
  • Advertisement
Sign in to follow this  
glu

OpenGL OpenGL Change Window Drawing Size

This topic is 1933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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();

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
 

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!