OpenGL / Moveing textures?

This is a discussion on OpenGL / Moveing textures? within the Game Programming forums, part of the General Programming Boards category; Hey. I have been makeing a pong game in OpenGL (the first *real* thing i am making in openGL) I ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    53

    OpenGL / Moveing textures?

    Hey.

    I have been makeing a pong game in OpenGL (the first *real* thing i am making in openGL)
    I have been useing the Nehe basecode (nehe.gamedev.com) and have been able to make 2 pods wich I can move up and down, I have been able to make a small box and add a texture to it so it looks like a ball.

    Now to my problem

    I cant get my "ball", wich is just a quad with a texture to it, to move.

    I have made my ball like this "glVertex3f(ballLTX, ballLTY, 0.0f);" so I am able to move it any way I want too.
    However If I put a code like this :

    Code:
    			if (keys['Q'])
    			{
    				while (ballLTX < 6.0f )
    				{
    					ballLTX+=0.05f;
    					ballRTX+=0.05f;
    					ballRBX+=0.05f;
    					ballLBX+=0.05f;
    
    		
    
    				}//end while
    
    
    			}//end if
    My box, or ball disaperase for some reason....Any help on this would be really great as I am out of ideas right now

    (please note that I am new to OpenGL)
    Its all a matter of willpower

  2. #2
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Post your rendering code - that won't help us.
    Do not make direct eye contact with me.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    53
    Not sure what bit of code you are after.. but this is what I have done to make the textured ball

    Code:
    
    glEnable (GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);glVertex3f(ballLTX, ballLTY, 0.0f);
    glTexCoord2f(1.0f, 0.0f);glVertex3f(ballRTX, ballRTY, 0.0f);
    glTexCoord2f(1.0f, 1.0f);glVertex3f(ballRBX, ballRBY, 0.0f);
    glTexCoord2f(0.0f, 1.0f);glVertex3f(ballLBX, ballLBY, 0.0f);
    glEnd();
    glDisable (GL_TEXTURE_2D);
    I have of cuase defined the ballLTX (ball, left top X), ballRTX (ball right top X) and so on
    Its all a matter of willpower

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    if (keys['Q'])
    			{
    				while (ballLTX < 6.0f )
    				{
    					ballLTX+=0.05f;
    					ballRTX+=0.05f;
    					ballRBX+=0.05f;
    					ballLBX+=0.05f;
    
    		
    
    				}//end while
    
    
    			}//end if
    That will change the ball's position before displaying it. Try removing the loop and possibly changing 0.05f to 0.01f (just to make sure it doesn't dissappear too quickly).

    Edit: Or maybe you meant that to be an if statement?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    are you redrawing the screen after the ball's position has been updated? make sure you glFlush() too.

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    53
    doh! Yes of cuase that should be a if...thanks for pointing it out...works now so thanks a lot

    btw...I might need some help later with figuering out how my box knows when it hits a pod but I will try a few things out first
    Its all a matter of willpower

  7. #7
    Banned
    Join Date
    Dec 2003
    Posts
    367
    It might be easier to just use a glTranslate instead of what you're doing. It'd be much easier to manage. Just a thought.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    1,199
    Yes just use glTranslatef instead, it will be much easier later on. To check if the ball hits one of the pods check the quad with the ball against the pods. For example:

    The ball quad has the size 16x16 and the pods has the size 8x64 pixels.
    Now calculate the middle coordinate for the ball quad and the pod quad (8,8 and 4, 32). Now lets say the ball is heading to the left. Check if the the balls top side is within the pods quad, if it is check if the balls left side is in the quad.

    Hope I gave you some hints on how to check for hits, its not the best but its working. I am currently using something similar to this method in my alpha game demo I have posted here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. openGL: textures, gluLookAt, and undefined behavior
    By MK27 in forum Game Programming
    Replies: 7
    Last Post: 04-28-2009, 10:12 AM
  2. Multiple textures in OpenGL...
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 02-12-2008, 07:24 AM
  3. OpenGL Again, Loading Textures onto Quads
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 05-07-2005, 08:14 PM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 04:16 PM
  5. OpenGL Dual Textures
    By drdroid in forum Game Programming
    Replies: 5
    Last Post: 01-02-2003, 05:59 PM

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