here's the problem: my triangle not rotating! Why? What I've done wrong?
Here's the code:
main.cpp
#include <iostream>
#include <GL/glut.h>
#include <GL/gl.h>
#include "myobject.h"
using namespace std;
Vector3f position = Vector3f(0.0f,0.0f,0.0f);
myobject *Ob = new myobject(position);
float _angle = 0.1f;
void render(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
_angle += 0.4f;
glPushMatrix();
glTranslatef (0.0f, -0.0f, -0.2f);
glRotatef(_angle, 1.0f, 0.0f, 0.0f);
Ob->draw();
glPopMatrix();
glutSwapBuffers();
}
void init(){
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(640, 480);
glutCreateWindow("test");
glutDisplayFunc(render);
glutMainLoop();
}
int main(int argc, char * argv[]) {
glutInit(&argc, argv);
init();
return 0;
}
myobject.cpp
#include <iostream>
#include <GL/glut.h>
#include <GL/gl.h>
#include "myobject.h"
using namespace std;
myobject::myobject(Vector3f pos)
{
_position = pos;
_size = 0.0f;
}
myobject::~myobject()
{
}
void myobject::draw()
{
glBegin(GL_TRIANGLES);
glColor3f(0.2f,0.2f,0.5f);
glVertex3f( 0.0f, 0.0f, 0.5f);
glVertex3f(-1.0f,-0.5f, 0.0f);
glVertex3f( 0.5f,-0.5f, 0.0f);
glEnd();
}
Are you sure you have animation running?
probably you just have to call glutPostRedisplay()
your render()
function.
That way GLUT will update the window and the animation.
Better option is to use:
glutIdleFunc(myIdle);
and:
void myIdle()
{
updateScene(deltaTime);
renderScene();
glutSwapBuffers();
}
Another thing: try to use modern opengl... not the old one...