0

我想在 OpenGL 中绘制一个简单的球体。

包括:

#include <GL/glew.h>
#include <GL/glfw.h>
#include <GL/glut.h>

还有一些人......

GLUquadric 声明

//before "infinite draw cycle"
GLUquadric* sphere;
sphere=gluNewQuadric();
gluQuadricNormals(sphere, GL_SMOOTH);

和“无限绘制周期”

do{
    // Clear the screen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Use our shader
    glUseProgram(programID);

    // Send our transformation to the currently bound shader 
    glUniformMatrix4fv(PID, 1, GL_FALSE, &Projection[0][0]);
    //kamera and directions vector defined elsewhere
    View = glm::lookAt(kamera,kamera+direction,up);
    glm::mat4 Model_View;
    glm::mat4 tempView;
    glm::mat4 Model;    

    //drawing some wall using vertexs
    tempView = glm::translate(View,glm::vec3(20,0,0));
    tempView = glm::rotate(tempView, 180.0f, glm::vec3(0,1,0));
    Model = glm::scale(glm::mat4(1.0f),glm::vec3(1,5,15));
    Model_View = tempView * Model;
    glUniformMatrix4fv(MVID, 1, GL_FALSE, &Model_View[0][0]);
    glDrawArrays(GL_TRIANGLES, 0,5*2*3);

    glColor3f(1.0f,0.0f,1.0f);
    gluSphere(sphere , 2 , 30 , 30);
    // Swap buffers
    glfwSwapBuffers();
}
while( condition... );

Ofc 我削减了有关其他一些对象绘图的代码部分。我刚开始使用 OpenGL (www.opengl-tutorial.org),不知道为什么这不起作用。没有编译错误,但存在运行时错误 1282 无效操作(函数 glGetError() 和 gluErrorString() )

什么可能是错的?

编辑 解决方案来自

glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);

glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
4

0 回答 0