0
所以,我試圖研究VBO,只是做了一些例子,但OpenGL是殺了我。我已經四個小時試圖做這個代碼工作,但我不知道爲什麼這個不工作。 我試圖用不同的顏色繪製4個方格。 但是,如果我嘗試使用GL_POINTS
畫我只看到在屏幕4點,應該是9分。如果我嘗試使用GL_QUADS
,它根本不會畫任何東西。 有趣的是,當我改變這一行:不能與緩衝區對象繪製
glDrawElements(GL_POINTS, 16, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
這樣:
glDrawElements(GL_POINTS, 64, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
OpenGL的繪製9點,而只是說,GL_QUADS不工作。 請,有人給我在這個問題上一盞燈,它的殺了我! 完整的代碼是在這裏:
#define GL_GLEXT_PROTOTYPES
#include<GL/glut.h>
#include<iostream>
using namespace std;
#define BUFFER_OFFSET(offset) ((GLfloat*) NULL + offset)
#define VERTICES 0
#define INDICES 1
#define NUM_BUFFERS 2
void init_2(){
GLuint buffers[NUM_BUFFERS];
GLfloat vertices[][3]= {
{0.0, 0.0, 0.0},
{0.0, 40.0, 0.0},
{0.0, 80.0, 0.0},
{40.0, 0.0, 0.0},
{40.0, 40.0, 0.0},
{40.0, 80.0, 0.0},
{80.0, 0.0, 0.0},
{80.0, 40.0, 0.0},
{80.0, 80.0, 0.0}
};
GLuint indices[][4] = {
{0, 1, 4, 3},
{1, 2, 5, 4},
{3, 4, 7, 6},
{4, 5, 8, 7}
};
glGenBuffers(NUM_BUFFERS, buffers);
glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
}
void display(void){
glPushMatrix();
glDrawElements(GL_POINTS, 16, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
glPopMatrix();
glutSwapBuffers();
}
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
gluOrtho2D((GLdouble) -1.0, (GLdouble) 90.0, (GLdouble) -1.0, (GLdouble) 90.0);
init2();
}
int main(int argv, char** argc) {
glutInit(&argv, argc);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("myCode.cpp");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}