我试图在新的Linux安装上使用一些OpenGL开发,无论我将顶点坐标更改为什么,我最终得到窗口正中心的一个点(小白点):
这是main.cpp:
#include <stdio.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include "math_3d.h"
GLuint VBO;
static void CreateVertexBuffer()
{
Vector3f Vertices[1];
这是我无法改变顶点坐标的地方:
Vertices[0] = Vector3f(0.5f, 0.5f, 0.0f);
我将GL_FLOAT
传递给glVertexAttribPointer
所以0.5f应该是X和Y的屏幕的1/2。
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
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_POINTS, 0, 1);
glDisableVertexAttribArray(0);
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(200, 200);
glutCreateWindow("Move you little Ass!");
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();
}
这里是math_3d.h中的Vector3f
结构:
struct Vector3f
{
float x;
float y;
float z;
Vector3f()
{
}
Vector3f(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
};