简体   繁体   English

glRotatef不旋转任何东西

[英]glRotatef does not rotate anything

here's the problem: my triangle not rotating! 问题是:我的三角形不旋转! Why? 为什么? What I've done wrong? 我做错了什么?

Here's the code: 这是代码:

main.cpp 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 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. 可能您只需要调用glutPostRedisplay()您的render()函数即可。 That way GLUT will update the window and the animation. 这样,GLUT将更新窗口和动画。

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... 另一件事:尝试使用现代的opengl ...而不是旧的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM