Jump to content
  • Advertisement
Sign in to follow this  
RySinfar

OpenGL Shrinking images on input (SOLVED, thank you)

This topic is 3161 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

I am new to OpenGL and I am workign on a fairly basic project. I have an image displayed on the screen and that image can be rotated by pressing the arrow keys, I can also create a menu and select things from the menu. Right now the image is a leaf (in 2d that can bend to become 3d), the issue I'm having is that whenever I click for the menu, left click to give the window focus, or use any keys on the keyboard, the image gets smaller. actually its more thinner to be exact. Some of the code is from superbible, including the code that rotates and the code that creates the menu. Here is the code that rotates. void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) xRot-= 5.0f; if(key == GLUT_KEY_DOWN) xRot += 5.0f; if(key == GLUT_KEY_LEFT) yRot -= 5.0f; if(key == GLUT_KEY_RIGHT) yRot += 5.0f; if(key > 356.0f) xRot = 0.0f; if(key < -1.0f) xRot = 355.0f; if(key > 356.0f) yRot = 0.0f; if(key < -1.0f) yRot = 355.0f; // Refresh the Window glutPostRedisplay(); } and then here is the code in the scene rendering function that I think is relevent void RenderScene(void) { // Clear the window glClear(GL_COLOR_BUFFER_BIT); // Draw back side as a polygon only, if flag is set if(iMode == MODE_LINE) glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); if(iMode == MODE_POINT) glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); if(iMode == MODE_SOLID) glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); GLfloat xchange = 0; GLfloat zchange = 0; glEnableClientState(GL_VERTEX_ARRAY); I really need to figure this out because the reduction is dramatic and it is messing with the work I am doing. I know it must be something I did (since superbible's example program didn't do this) but I have no idea what! If you need more information let me know. [Edited by - RySinfar on October 28, 2009 11:13:29 AM]

Share this post


Link to post
Share on other sites
Advertisement
Yes there is a

// Restore transformations
glPopMatrix();

// Flush drawing commands
glutSwapBuffers();

at the end of RenderScene()

Share this post


Link to post
Share on other sites
Quote:
Original post by RySinfar
I really need to figure this out because the reduction is dramatic and it is messing with the work I am doing.


In that case you probably shouldn't compare the value of key with angles.

Share this post


Link to post
Share on other sites
Funny indeed that bug is on the book OpenGL SuperBible, that im currently reading (for refreshing opengl too long away T_T).

In any case try the glLoadIdentity tip, given above, also i see you're setting the polygon mode each rendered frame, altought not related to your question you could optimize that and change it only on key presseds or instead of defining your constants use opengl constants or, match yours to equal opengl, for instance

GLenum ePolygonModel = GL_FILL;

...
if(key ....)
ePolygonModel = GL_LINES;


also if(..)
then else if(...)

syntax performs better thant multiple if statments.

In any case try the glLoadIdentity();

Share this post


Link to post
Share on other sites
EDIT: I figured it out I think. I am performing the sin function again on the already sin functioned leaf. Thats why its shrinking life it does, because the sin function is doing it. I forgot that I had meant to put in a second variable to hold the temporary adjusted values of the leaf!

Yep I tested it out and that was the issue, thanks for the help though and I am sorry for any inconvenience.

[Edited by - RySinfar on October 28, 2009 11:08:09 AM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!