Change Animation in OpenGL

Started by
20 comments, last by Green_Baron 4 years, 11 months ago
 
 
1
9 hours ago, GoliathForge said:

I already did.   When I saw that you were using immediate mode opengl, I pulled one of my older frameworks and replaced the content of my update and draw methods with the code posted above. Nothing else hidden. You are more than welcome to browse my ogl2 framework code if you wish.  A link to the source I used is in this album, but again, on topic sample code is in the post above.  

 

Thanks so much again for sharing the great source.

I will try to implement my code then can show here.

I think that I need to improve the C++ knowledge in OpenGL, especially in 3D computer graphic. 

Advertisement
 
 
 
On 5/20/2019 at 10:00 PM, GoliathForge said:

 

I have another problem below:

If I press "w" there are 5 cubes will appear at the same time. How can I make 5 cubes in 5 times press the 'w' key?

Would you please give comments.


int countcube(0);

bool presskey(false);


void drawBox(int i) {

    glPushMatrix();
    glTranslatef(i+0.5, i+0.5, 0.5);
    glColor3f(0.5,0.0, 1.5);
    glutWireCube(1);
    glPopMatrix();

}

void displayCube(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ZERO);

    SetLight();

    glPushMatrix();

    for (int i(0); i < 5; i++) {
        drawBox(i);
    }

    glPopMatrix();
    glutSwapBuffers();
}

void keyCube(unsigned char key, int x, int y) {

    switch (key) {
    case 'w':
        if (presskey == true)
        {
            countcube++;
            glutPostRedisplay();
          
        }
        else
        {
           
        }

         break;
    }
}

 

I see a problem that although pressing key 1 time, the displayCube(void) runs many times.

So, if we use the for loop inside the the displayCube(void) function, the loop will run many times.

for examples, when I press 'w' key, i variable will run from 0 to 5 many times, it means all cubes will appear.

When I delete the for loop, it may work. 

How can we avoid it?  with still using for loop inside display() function.

I have absolutely zero experience with glut. Do you have the version that has glutKeyboardUpFunc and glutKeyboardFunc? This might be a good opportunity to build a real handler before moving on to graphics.

http://www.swiftless.com/tutorials/opengl/keyboard.html looks like a standard approach within glut. The next option might be GetAsyncKeyState, part of the windows api, when you experience multiple keypress restrictions. 

 

More of a general question out of curiosity: is there a special reason why you guys use OpenGL 2, which became out style long ago ? Even glut is outdated and freeglut's latest release is from 2015 or so ?

Or am i missing something ?

53 minutes ago, Green_Baron said:

is there a special reason why you guys use OpenGL 2

I asked this question yesterday.

 When you're a beginner, does it really matter? If all you need is alpha blending and we're not lighting pixel art, then fixed function seems perfectly acceptable. When you say out of style long ago, are you saying should not be used at all?

I'll say again, glut I've never used, but looking at it now, there were some interesting aspects of it that seem worth experiencing if you have not. I think many of us loose sight of the prize. We think the uber shader will make our game into something it isn't. I know I spent many years focused on the eye candy when the real fun factor goodness was not in any of the rendering api's or cross platform helper libraries.

Just an opinion.

I have never done it the old way ... I totally lack your experience, came here just shortly.

It is only (if i am not mistaken), the newfangled pipeline way does things so much different and makes so much better use of today's hardware (correct me if that's incorrect) that it might be in vain to spend too much time learning the old way.

The glut family isn't maintained any more (i think). glfw for example leaves the control of the loop totally to the programmer and supports various platforms and Vulkan.

My question would be, @tamlam, have you considered using "modern" OpenGL and actually decided not to use it for reasons ? You'd get much more help when using OpenGL >3.3, i'd say ...

 

6 hours ago, GoliathForge said:

I have absolutely zero experience with glut. Do you have the version that has glutKeyboardUpFunc and glutKeyboardFunc? This might be a good opportunity to build a real handler before moving on to graphics.

http://www.swiftless.com/tutorials/opengl/keyboard.html looks like a standard approach within glut. The next option might be GetAsyncKeyState, part of the windows api, when you experience multiple keypress restrictions. 

 

Thanks, GoliathForge.

I got these ideas. However, I think the problems related to the callback function. I am trying to fix this problem ^^ before changing to modern OpenGL.

 
 
 
2
3 hours ago, Green_Baron said:

My question would be, @tamlam, have you considered using "modern" OpenGL and actually decided not to use it for reasons ? You'd get much more help when using OpenGL >3.3, i'd say ...

hi, I have just started the simple project with the old version. I can improve programming skill in computer graphics.

After finishing this project, I may change to Modern OpenGL.

Ok then.

Allow me to leave this nice introduction into OpenGL here. It discusses your case (model transformations depending on time) under "Getting started" - "Transformations".

Hope you solve it !

This topic is closed to new replies.

Advertisement