我正在使用this tutorial来学习一些OpenGL。
但是代码不起作用 - 没有显示三角形。但是,绘制了上一个教程页面中的(0 | 0 | 0)点。
这是我的代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "vector3f.hpp"
GLuint VBO;
static void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}
static void CreateVertexBuffer()
{
Vector3f Vertices[3];
Vertices[0] = Vector3f(-.5f, -.5f, .0f);
Vertices[1] = Vector3f(.5f, -.5f, .0f);
Vertices[2] = Vector3f(.0f, .5f, .0f);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
int main(int argc, char* argv[]) {
short w = 640, h = 480;
short sw, sh;
setenv("DISPLAY", ":0.0", 0);
glutInit(&argc, argv);
sw = glutGet(GLUT_SCREEN_WIDTH);
sh = glutGet(GLUT_SCREEN_HEIGHT);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(w, h);
glutInitWindowPosition((short)(sw-w)/2, (short)(sh-h)/2);
glutCreateWindow("Tutorial 03");
InitializeGlutCallbacks();
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
return 1;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateVertexBuffer();
glutMainLoop();
return 0;
}
为什么不工作?我已经链接了所有库(libGL.so,libglut.so,libGLEW.so)
我正在使用Ubuntu Raring x64