Jump to content

  • Log In with Google      Sign In   
  • Create Account


OpenGL Change Window Drawing Size


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 glu   Members   -  Reputation: 115

Like
0Likes
Like

Posted 31 March 2013 - 10:06 AM

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

Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7564

Like
0Likes
Like

Posted 31 March 2013 - 10:16 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 glu   Members   -  Reputation: 115

Like
0Likes
Like

Posted 31 March 2013 - 11:38 AM

 

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS