943,808 Members | Top Members by Rank

Ad:
Aug 22nd, 2009
0

OpenGL - displaying issue (reshape func)

Expand Post »
Hello,
my problem is of that kind beginners use to have. After following some glut tutorials I've decided it's time to do something small generally on my own. An obstacle appeared at the very beginning.

At the moment I got stuck, all my code was supposed to do was drawing a primitive using an ortagonal transformation to display it. Apperently, I failed at coding the latter.

c++ Syntax (Toggle Plain Text)
  1. void reshape (int w, int h)
  2. {
  3. if (h==0)
  4. {
  5. h=1;
  6. }
  7.  
  8. glViewport(0,0,w,h);
  9. glMatrixMode (GL_PROJECTION);
  10. glLoadIdentity();
  11.  
  12. glOrtho(0.0f,w,h,0.0f,-1.0f,1.0f);
  13. glMatrixMode(GL_MODELVIEW);
  14. glLoadIdentity();
  15. }

and the drawing func("bobby's" variables x and y are holding float values, tried with various bare numbers too):

c++ Syntax (Toggle Plain Text)
  1. void DrawScene(void)
  2. {
  3. glPushMatrix();
  4. glTranslatef(bobby.x, bobby.y, 0.0f);
  5.  
  6. glColor3f(1.0f, 0.0f, 0.0f);
  7. glBegin(GL_TRIANGLES);
  8.  
  9. glVertex2d(-0.2, -0.2);
  10. glVertex2d(0.2, 0.2);
  11. glVertex2d(0.2, -0.2);
  12.  
  13. glEnd();
  14. glPopMatrix();
  15. glutSwapBuffers();
  16. }

Guess I could solve this with a little help of an example code, but I'd like to understand what I'm doing. Thanks.
Similar Threads
Yle
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Yle is offline Offline
2 posts
since Aug 2009
Aug 22nd, 2009
0

Re: OpenGL - displaying issue (reshape func)

I don't know what other calls you have there...

but first make sure everything is off:

C++ Syntax (Toggle Plain Text)
  1. glDisable(GL_TEXTURE_2D);
  2. glDisable(GL_BLEND);
  3. glDisable(GL_ALPHA);


Then...

Also it looks from there that Ortho Call is too vast scaled. Ortho sets a cordinte system. Your cordinate system goes from 0 to w (or h), thus scale is 1024 on both sides. If you draw then a Triangle with 0.2, guess where it is? Probably in the vast space of the opengl universe...

Either change glOrtho

double itsUnit=1.0f;
double itsRatio=1024.0f/768.0f;

glOrtho(0.0, itsUnit*itsRatio, 0.0, itsUnit, 0, 10);

or Change the size of your trinagle..

glVertex2d(-400, -400);

Could be other things as well, but for that I would need to see the whole code.

&Cheers,

poliet
Last edited by poliet; Aug 22nd, 2009 at 9:33 pm.
Reputation Points: 10
Solved Threads: 2
Light Poster
poliet is offline Offline
27 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: Direct3D9 Sprite issues with rotation.
Next Thread in Game Development Forum Timeline: falling of a bmp under gravity - glut





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC