1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
void OGLAbstr::renderFrame()
{
glClear(GL_COLOR_BUFFER_BIT);
renderPrimitive();
//Rendering code
SwapBuffers(hDC);
}
bool OGLAbstr::addPrimitive(const float vPos[])
{
/*GLuint VertexBuffer;
glGenBuffers(1, &VertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vPos), vPos, GL_STATIC_DRAW);
// glBindBuffer(GL_ARRAY_BUFFER, 0);
canRender = true;
*/return true;
}
void OGLAbstr::renderPrimitive()
{
/*if(canRender)
{
glUseProgram(shaderProgram);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
}*/
if(test_draw)
{
glDrawArrays(GL_TRIANGLES, 0, 3);
}
}
bool OGLAbstr::testDraw()
{
const float data[] =
{
0.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
glGenVertexArrays(1,&testDrawVAO);//<----------------------- Exception
glBindVertexArray(testDrawVAO);
GLuint vBuf;
glGenBuffers(1, &vBuf);
glBindBuffer(GL_ARRAY_BUFFER, vBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
GLuint shProg;
shProg = shader->loadBasicShaders();
glUseProgram(shProg);
GLuint vPosition = glGetAttribLocation( shProg, "vPosition" );
glEnableVertexAttribArray( vPosition );
glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, 0);
test_draw = true;
return true;
}
|