我想在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);
和“inifite draw cycle”
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);