Trouble with OpenGL - "The Incredible Shrinking Magnolias"

This is a discussion on Trouble with OpenGL - "The Incredible Shrinking Magnolias" within the Game Programming forums, part of the General Programming Boards category; Hey... if I'm being an idiot and miss something important you need to know, just hit me up for it ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    5

    Trouble with OpenGL - "The Incredible Shrinking Magnolias"

    Hey... if I'm being an idiot and miss something important you need to know, just hit me up for it and I'll post it ASAP (Don't think of me as a forum n00b please) :-)

    The following code does the following (In theory)

    1. Draws 4 flowerpots, one without a flower in it
    2. Draws a watering can
    3. As you move the mouse, the view changes (through Ortho2D taking it's viewport from where the mouse is)

    The BIG PROBLEM is that when I move the mouse a single pixel, the flower suddenly shrinks. Help would be appreciated in determining the cause.

    Source code in the text file attached.

    Thank you to anyone who can help.
    Attached Files Attached Files

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    You dont seem to clearly understand the intentions of glPushMatrix() and glPopMatrix(). You have them randomly positioned throughout your code. have a look here:

    http://pyopengl.sourceforge.net/docu...hMatrix.3G.xml
    (yes, its for pyopengl but the C docs are there too )

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    5
    Quote Originally Posted by Perspective
    You dont seem to clearly understand the intentions of glPushMatrix() and glPopMatrix(). You have them randomly positioned throughout your code. have a look here:

    http://pyopengl.sourceforge.net/docu...hMatrix.3G.xml
    (yes, its for pyopengl but the C docs are there too )
    They're at the beginning of each function so that before it does ANYTHING in the function, it...

    1. Reloads the pushed position
    2. saves the current position
    3. does the function
    4. Start a new function (Which will go to "1.")

    This makes it so that further transformations will start from the same place... mostly to help me with working out where to put things.

  4. #4
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Perspective is right, I see these lines in a few spots:
    Code:
    glPopMatrix();     			
    glPushMatrix();
    This isn't the best way to handle the matrix stack. I see what your intent is, and you almost have it correct. but it is much better to have each draw function handle itself like so:
    Code:
    glPushMatrix();
       //draw
    glPopMatrix();
    It is easier to maintain the stack this way. If you were to follow that pattern, you wouldn't have that glPopMatrix() call in Mouse() which is what I believe is the problem.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    5
    Quote Originally Posted by skorman00
    Perspective is right, I see these lines in a few spots:
    Code:
    glPopMatrix();     			
    glPushMatrix();
    This isn't the best way to handle the matrix stack. I see what your intent is, and you almost have it correct. but it is much better to have each draw function handle itself like so:
    Code:
    glPushMatrix();
       //draw
    glPopMatrix();
    It is easier to maintain the stack this way. If you were to follow that pattern, you wouldn't have that glPopMatrix() call in Mouse() which is what I believe is the problem.
    Gah! Now the flower dissappears when I move the mouse and I have NO idea what it does with it!

    I've made a couple other changes too (as advised by my lecturer) but I can't find exactly what makes it go so bad!
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble with openGL
    By getinhigh4life in forum Game Programming
    Replies: 4
    Last Post: 08-05-2008, 03:36 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  3. Texture Mapping Trouble With Opengl
    By drdroid in forum Game Programming
    Replies: 9
    Last Post: 06-03-2003, 02:18 PM
  4. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21