Thread: lots of questions about opengl

  1. #1
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67

    lots of questions about opengl

    alright, i'm making my first opengl program, pong, and as i don't know a lot about opengl, so i've been coming up with my own solutions for problems such as moving the paddles, and it's probably hideously impractical.

    first, i constructed the blocks and the pong square with glBegin (GL_POLYGON), but i defined their x vertices with a previously declared array. when i do a WM_KEYDOWN it activates a function that does a loop to add or subtract to the coordinate numbers. as you can imagine, it doesn't flow too well. i've got the buffer swapping working, so that's not a problem, it's just being really jerky.

    what should i do to move the blocks besides what i'm doing, and what's a better way to initiate the movement than WM_KEYDOWN?
    also, what's the naming convention for the keys with KEYDOWN? i only know VK_ESCAPE, but my guesses for the other ones don't work.
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  2. #2
    Registered User
    Join Date
    Jun 2006
    Posts
    47

    Re:

    Did you try using GLUT, instead? That's what I use. It's keyboard controls are great. You could also try glTranslate() to move the paddles around.

  3. #3
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    any descriptions on how to actually use that stuff? how does translate() work, and how do i implement GLUT?
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    47
    Okay. In order for you to use GLUT, you have to download the glut32.dll file, and the header file. Put the header file in your include folder(/Include/GL/). Make sure that -lglut32 is used when compiling. I like to use Dev-C++, because that makes all of it easy.

    That's about all you have to do for GLUT. It also is very portable, and often works on all Operating Systems.

    Here's alot about glTranslate.

    http://www.mevis.de/opengl/glTranslate.html

  5. #5
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    yeah, all that stuff with the libraries is easy, but how do you actually implement it? does it have a seperate set of keyboard functions?
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    47
    You put the <GL/glut.h> at the top, and then there is a display() function that you put all the code in, or put links to other functions where code is written. Here is an example of a code that draws a few white dots.

    Code:
    void points(void)
     {
      glBegin(GL_POINTS);
       glColor3f(1.0,1.0,1.0);
       glVertex3f(0.4,0.2,0.0);
       glVertex3f(0.2,0.7,0.0);
      glEnd();
     }
    And there are functions like this for a keyboard:

    Code:
    void SpecialKeyHandler(int key,int x,int y)
    {
     switch(key)
     {
     case GLUT_KEY_UP:
     y1+=6;
     break;
     case GLUT_KEY_DOWN:
     y1-=4;
     break;
     case GLUT_KEY_LEFT:
     x1-=1;
     break;
     case GLUT_KEY_RIGHT:
     x1+=1;
     break;
     default:
     break;
    }
    }
    There are mouse functions, special keyboard functions, and regular keyboard functions. It is the easiest way to make a game with OpenGL I know of!

  7. #7
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    about translate, how exactly do i use that on one particular set of coordinates? do i need to set up a class and make each paddle a different object?
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  8. #8
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    do i need to set up a class and make each paddle a different object?
    That would be alright. Here is how I would write one: (I may miss a few variables; please correct me if I'm wrong)

    Paddle
    public:
    Paddle()
    ~Paddle()
    int set_pos(float x, float y)
    int set_vel(float x, float y)
    int state;
    float x,y;
    float x_vel, y_vel;
    std::string image_filename;
    image data;

    Where image is a container-type object that would hold the main part of the data. Alternativley, you could store image_filename inside data.

    --Joe
    Last edited by joeprogrammer; 06-30-2006 at 04:41 PM.

  9. #9
    Registered User
    Join Date
    Dec 2003
    Posts
    50
    Hi,

    There is a set of GLUT tutorials from this URL: http://www.lighthouse3d.com/opengl/glut/index.php?1

    Best Reagrds,
    Yeoh

  10. #10
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Quote Originally Posted by n3v
    about translate, how exactly do i use that on one particular set of coordinates? do i need to set up a class and make each paddle a different object?
    Joeprogrammer's class implementation is the easiest way to setup a pong class, and this is the simplest way to use translate (i will use quad)

    Code:
    glTranslatef(xMove, yMove, zMove);   //define the variables somewhere;
    glBegin(GL_QUADS);
           glVertex3f(0, 0, 0);         
           glVertex3f(2, 0, 0);
           glVertex3f(2, 1, 0);
           glVertex3f(0, 1, 0);
    glEnd();
    
    //these vertices assume that you're using glPerspective
    Now, if you're not using 3D, use "glTranslated(x, y)" and "glVertex2d(x, y)". All you have to do now is make the a link when the button is press and transfer it back to the paddle class.
    Hello, testing testing. Everthing is running perfectly...for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Really new & Really clueless (lots of different questions)
    By Tigerfeet in forum C++ Programming
    Replies: 7
    Last Post: 11-07-2008, 04:32 PM
  2. SDL_ttf and OpenGL
    By sand_man in forum Game Programming
    Replies: 2
    Last Post: 12-01-2004, 06:06 PM
  3. OpenGL lighting
    By BabyG in forum Game Programming
    Replies: 3
    Last Post: 08-29-2004, 09:58 AM
  4. So.. what's the difference between DirectX and OpenGL?
    By QuestionC in forum Game Programming
    Replies: 6
    Last Post: 01-19-2002, 06:18 PM
  5. OpenGL question
    By Malek in forum Windows Programming
    Replies: 1
    Last Post: 09-10-2001, 12:00 PM