Results 1 to 2 of 2

Thread: updating frame prob

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    poole,england
    Posts
    15

    updating frame prob

    I'm having trouble with this source that moves the camera with the cursor keys. I can't get it to redraw the frame, so that there's no movement. I've tried using the glutIdleFunc but the compiler gives following error:

    118 C:\Program Files\c++\Dev-Cpp\ben-prog\glgrid3.cpp
    invalid conversion from `void (*)(int, int)' to `void (*)()'

    Also, when I use glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); as oppose to GLUT_SINGLE, all I get is a blank screen.
    What do I need to update frame?

    #include <math.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include <GL/glut.h>
    #include <stdlib.h>

    static float angle=0.0,ratio;
    static float x=0.0f,y=1.75f,z=5.0f;
    static float lx=0.0f,ly=0.0f,lz=-1.0f;
    static GLint snowman_display_list;

    void init(void)
    {
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_FLAT);
    }
    void Draw3DSGrid(void)
    {
    // This function was added to give a better feeling of moving around.
    // A black background just doesn't give it to ya We just draw 100
    // green lines vertical and horizontal along the X and Z axis.

    // Turn the lines GREEN
    glColor3ub(0, 255, 0);

    // Draw a 1x1 grid along the X and Z axis'
    for(float i = -50; i <= 50; i += 1)
    {
    // Start drawing some lines
    glBegin(GL_LINES);

    // Do the horizontal lines (along the X)
    glVertex3f(-50, 0, i);
    glVertex3f(50, 0, i);

    // Do the vertical lines (along the Z)
    glVertex3f(i, 0, -50);
    glVertex3f(i, 0, 50);

    // Stop drawing lines
    glEnd();
    }
    }
    void display(void)
    {
    glClear (GL_COLOR_BUFFER_BIT);
    //glPushMatrix();
    glColor3f (1.0, 1.0, 1.0);
    glLoadIdentity (); /* clear the matrix */
    /* viewing transformation */
    gluLookAt(x, y, z,
    x + lx,y + ly,z + lz,
    0.0f,1.0f,0.0f);

    //gluLookAt (0.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glScalef (1.0, 2.0, 1.0); /* modeling transformation */
    glutWireCube (1.0);
    Draw3DSGrid();
    //glPopMatrix();
    glFlush ();
    }
    void reshape (int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
    glMatrixMode (GL_MODELVIEW);
    glutSwapBuffers();
    }

    void orientMe(float ang) {

    lx = sin(ang);
    lz = -cos(ang);
    glLoadIdentity();
    gluLookAt(x, y, z,
    x + lx,y + ly,z + lz,
    0.0f,1.0f,0.0f);
    }
    void moveMeFlat(int direction) {
    x = x + direction*(lx)*0.1;
    z = z + direction*(lz)*0.1;
    glLoadIdentity();
    gluLookAt(x, y, z,
    x + lx,y + ly,z + lz,
    0.0f,1.0f,0.0f);
    }

    void inputKey(int key, int x, int y) {

    switch (key) {
    case GLUT_KEY_LEFT :
    angle -= 0.01f;
    orientMe(angle);break;
    case GLUT_KEY_RIGHT :
    angle +=0.01f;
    orientMe(angle);break;
    case GLUT_KEY_UP :
    moveMeFlat(1);break;
    case GLUT_KEY_DOWN :
    moveMeFlat(-1);break;
    }


    }

    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    init();
    glutSpecialFunc ( inputKey );
    glutDisplayFunc(display);
    glutIdleFunc(reshape);

    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;
    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: updating frame prob

    I see two things you don't have an idle routine, you just used you reshape routine as you idle.

    Also you have you glutSwapBuffers in your resphape routine, it should be at the end of your display routine.


    In these two routines you are repeating code that is already in your display routine, remove it since it does nothing.

    Code now should look like these:

    void orientMe(float ang) {

    lx = sin(ang);
    lz = -cos(ang);

    }

    void moveMeFlat(int direction) {
    x = x + direction*(lx)*0.1;
    z = z + direction*(lz)*0.1;

    }




    [This message has been edited by nexusone (edited 07-27-2003).]

Similar Threads

  1. Drawing outside of clip space vs. updating VBO every frame
    By thealik in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-03-2018, 03:23 PM
  2. Updating textures per frame
    By debinair in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 08-25-2016, 10:53 AM
  3. Updating VAO data every frame not working
    By mobeen in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 02-12-2011, 10:25 AM
  4. frame updating
    By JazzD in forum OpenGL ES
    Replies: 4
    Last Post: 10-20-2004, 09:50 PM
  5. updating a texture at every frame
    By franz1999 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-18-2003, 07:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean