OpenGL - displaying issue (reshape func)

Thread Solved

Join Date: Aug 2009
Posts: 2
Reputation: Yle is an unknown quantity at this point 
Solved Threads: 0
Yle's Avatar
Yle Yle is offline Offline
Newbie Poster

OpenGL - displaying issue (reshape func)

 
0
  #1
Aug 22nd, 2009
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.

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

  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 27
Reputation: poliet is an unknown quantity at this point 
Solved Threads: 2
poliet poliet is offline Offline
Light Poster

Re: OpenGL - displaying issue (reshape func)

 
0
  #2
Aug 22nd, 2009
I don't know what other calls you have there...

but first make sure everything is off:

  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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC