Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

OpenGL render scene question

Options
  • 05-04-2004 10:48pm
    #1
    Closed Accounts Posts: 1,135 ✭✭✭


    I have created an OpenGL scene with c++ and am now minipulating an object ... thing is I can't see it moving untill all the tasks are done. I tried calling
    DrawGLScene() after each seperate tast ... but got two errors.

    1. DrawGLScene() ... undeclared Identifier
    2. int DrawGLScene(GLvoid) ... redefinition, different type modifiers

    I need it to return a value .. so I tried int num=DrawGLScene() .. so the value would be going somewhere .. but that didn't work ... and also tried changing to
    int DrawGLScene() .. incase the GLvoid was messing it up .. but still no joy . :(

    Any suggestions appriciated?


Comments

  • Closed Accounts Posts: 104 ✭✭GiMiC


    You're using the GLUT libraries I assume? If you are then there's little you can do to change the definition of that function (DrawGLScene) as the glutDisplayFunc function expects it to take no parameters and return no values.

    If you're using complete Win32 and OpenGL code (i.e. no other libraries) the you'll just need to redefine the function to return a value in it's protype.

    I could go on a bit more, but I'm not sure I understand exactly what the problem is. Maybe post the source to the program?


  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    I'd say it's something more simple, like you're calling DrawGLScene() in a function above where you define it. Yeah let's see some code.


  • Closed Accounts Posts: 1,135 ✭✭✭KlodaX


    Yeah .... I am simple. :rolleyes: ... calling it before defining it.

    Still have the same problem. Its a rubiks' cube and I want to display the twists. It works away solving itself but doesn't display untill its complete. I want it to display the twists. I tried swapping buffers aswell but that didn't work either.. here is the code:

    [PHP]int TwistCube(int axis, int side, int twistdir)
    {


    for(int count=0; count<27; count++)
    {
    rubiks[count].rotate_cuboid(axis, side, twistdir);
    }
    DrawGLScene();
    //SwapBuffers(hDC);

    return TRUE;
    }



    int DrawGLScene(GLvoid)
    {


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();


    gluLookAt( g_Camera.m_Position.x, g_Camera.m_Position.y, g_Camera.m_Position.z,
    g_Camera.m_View.x, g_Camera.m_View.y, g_Camera.m_View.z,
    g_Camera.m_upVector.x, g_Camera.m_upVector.y, g_Camera.m_upVector.z);


    glRotatef(y_angle,0.0f,1.0f,0.0f);
    glRotatef(x_angle,1.0f,0.0f,0.0f);

    count=0;

    xloop=0;
    yloop=1;
    zloop=0;

    for(count=0;count<27; count ++)
    {
    glPushMatrix();
    if(rubiks[count].pos[2]==1)
    {
    glRotatef(z_twist, 0.0f, 0.0f, 1.0f);
    }
    else if(rubiks[count].pos[1]==1)
    {
    glRotatef(y_twist, 0.0f, 1.0f, 0.0f);
    }
    else if(rubiks[count].pos[0]==1)
    {
    glRotatef(x_twist, 1.0f, 0.0f, 0.0f);
    }


    //update_view(angle_view);
    rubiks[count].draw_cuboid(texture);
    glPopMatrix();
    }


    return TRUE;
    }[/PHP]


  • Closed Accounts Posts: 104 ✭✭GiMiC


    Well without seeing the full source code I can't be sure, but if you're getting a "undeclared Identifier", or similar error, then it's likely due to your functions being in the wrong order (or you never made prototypes for them).

    In your TwistCube function you make a call to the DrawGLScene function, but this isn't defined till after the TwistCube function and hence doesn't exist yet. To solve this either move the DrawGLScene function above the TwistCube function, or else add function protypes for each of your functions at the beginning of the source file.

    For example, the prototype for your DrawGLScene would be:

    int DrawGLScene(GLvoid);

    so just add this line below all your #include lines and that should help.


  • Closed Accounts Posts: 1,135 ✭✭✭KlodaX


    my bad .. I should have mentioned ... they aren't in that order in the application .. the whole thing is about 60 printed pages long .. I don't think it would post on the forum! :) ... I'm not getting any compile errors anymore .. but calling the draw scene isn't doing anything at all.
    is that all I'm ment to do to get it to update on the screen?


  • Advertisement
  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    Why have you commented out the SwapBuffers()? I guess you must be doing it somewhere else.... right?!
    It probably won't make a difference but try sticking a glFlush(); at the end of DrawGLScene(), just to make sure all the commands are flushed.

    Also, try changing the glClearColor() to a random colour every frame. If the picture still doesnt change colour then it's more likely a windowing/context (or buffering...) problem. If it does, then you might just have the camera pointing in the wrong direction!!


  • Closed Accounts Posts: 1,135 ✭✭✭KlodaX


    I CAN'T BELIEVE IT!

    flushing the buffer worked... Jazz you gem. Thanks again! :D


  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    Hmm I never put a glFlush() in my programs, because it never seems to do anything... but there you go!


Advertisement