任何人都知道爲什麼這個代碼在openGL 3.1中顯示一個三角形,但在3.2中沒有任何東西?openGL 3.1中的三角形,但3.2中沒有任何東西
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/glfw.h>
GLuint myVBO;
void onDraw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, myVBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glfwSwapBuffers();
}
void loadData() {
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
glGenBuffers(1, &myVBO);
glBindBuffer(GL_ARRAY_BUFFER, myVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
}
void createWindow() {
int w=800,h=600;
if(glfwInit() != GL_TRUE){
return;
}
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); //change to 1 to see the triangle
//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if(!glfwOpenWindow(w,h,5,6,5,0,8,0,GLFW_WINDOW)){
glfwTerminate();
return;
}
if(glewInit() != GLEW_OK){
return;
}
printf("Version: %s\n", glGetString(GL_VERSION));
printf("Error: %d\n", glGetError());
}
int main() {
createWindow();
loadData();
while(1){onDraw();}
return 0;
}
基於第一2個教程上http://www.opengl-tutorial.org/ 我的輸出是
Version: 3.2.0 NVIDIA 295.49
Error: 1280
看看是否有幫助:http://www.opengl.org/wiki/OpenGL_Loading_Library –
不在glew部分,glewExperimental = TRUE好像不相關 – Inuart