void TriangleScene::initialise()

{

//return if already initialized

if(mInitialized)

return;

if(!initializeOpenGLFunctions())

{

std::cerr << "Modern OpenGL Functions could not be initialized." << std::endl;

std::exit(EXIT_FAILURE);

}

GL_CHECK_ERRORS;

//make the projection and model-view matrix

//identity matrices

mProjectionMatrix = glm::mat4(1.0f);

mModelViewMatrix = glm::mat4(1.0f);

loadShaders();

//setup the triangle geometry

mVertices[0].color = glm::vec3(1.0,0.0,0.0);

mVertices[1].color = glm::vec3(0.0,1.0,0.0);

mVertices[2].color = glm::vec3(0.0,0.0,1.0);

mVertices[0].position = glm::vec3(-1,-1,0);

mVertices[1].position = glm::vec3(0,1,0);

mVertices[2].position = glm::vec3(1,-1,0);

//setup the triangle indices

mIndices[0] = 0;

mIndices[1] = 1;

mIndices[2] = 2;

//check for opengl errors

GL_CHECK_ERRORS;

//setup the triangle vao and vbo stuff

glGenVertexArrays(1,&mVaoID);

glGenBuffers(1,&mVerticesID);

glGenBuffers(1,&mIndicesID);

//get the size of the Vertex struct

GLsizei stride = sizeof(Vertex);

glBindVertexArray(mVaoID);

glBindBuffer(GL_ARRAY_BUFFER,mVerticesID);

//pass triangle vertices to the buffer object

glBufferData(GL_ARRAY_BUFFER, //specifies the target buffer object

sizeof(mVertices),//specifies the size in bytes

&mVertices[0], // pointer to the data

GL_STATIC_DRAW); //usage pattern of the data

GL_CHECK_ERRORS;

glEnableVertexAttribArray(mTriangleShader->getAttribute("vVertex"));

glVertexAttribPointer(mTriangleShader->getAttribute("vVertex"),3,GL_FLOAT,GL_FALSE,stride,0);

GL_CHECK_ERRORS;

//enable vertex attribute array for the color

glEnableVertexAttribArray(mTriangleShader->getAttribute("vColor"));

glVertexAttribPointer(mTriangleShader->getAttribute("vColor"),3,GL_FLOAT,GL_FALSE,stride,(const GLvoid*)offsetof(Vertex,color));

GL_CHECK_ERRORS;

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mIndicesID);

glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(mIndices),&mIndices[0],GL_STATIC_DRAW);

glDisableVertexAttribArray(mTriangleShader->getAttribute("vVertex"));

glDisableVertexAttribArray(mTriangleShader->getAttribute("vColor"));

glBindVertexArray(0);

GL_CHECK_ERRORS;

mInitialized = true;

}

I think the issue lies here and I am examining it right now. Any hint from your end within the function will accelerate the process.

Thanks

void TriangleScene::initialise()
{
//return if already initialized
if(mInitialized)
return;
if(!initializeOpenGLFunctions())
{
std::cerr << "Modern OpenGL Functions could not be initialized." << std::endl;
std::exit(EXIT_FAILURE);
}
GL_CHECK_ERRORS;
//make the projection and model-view matrix
//identity matrices
mProjectionMatrix = glm::mat4(1.0f);
mModelViewMatrix = glm::mat4(1.0f);
loadShaders();
//setup the triangle geometry
mVertices[0].color = glm::vec3(1.0,0.0,0.0);
mVertices[1].color = glm::vec3(0.0,1.0,0.0);
mVertices[2].color = glm::vec3(0.0,0.0,1.0);
mVertices[0].position = glm::vec3(-1,-1,0);
mVertices[1].position = glm::vec3(0,1,0);
mVertices[2].position = glm::vec3(1,-1,0);
//setup the triangle indices
mIndices[0] = 0;
mIndices[1] = 1;
mIndices[2] = 2;
//check for opengl errors
GL_CHECK_ERRORS;
//setup the triangle vao and vbo stuff
glGenVertexArrays(1,&mVaoID);
glGenBuffers(1,&mVerticesID);
glGenBuffers(1,&mIndicesID);
//get the size of the Vertex struct
GLsizei stride = sizeof(Vertex);
glBindVertexArray(mVaoID);
glBindBuffer(GL_ARRAY_BUFFER,mVerticesID);
//pass triangle vertices to the buffer object
glBufferData(GL_ARRAY_BUFFER, //specifies the target buffer object
sizeof(mVertices),//specifies the size in bytes
&mVertices[0], // pointer to the data
GL_STATIC_DRAW); //usage pattern of the data
GL_CHECK_ERRORS;
glEnableVertexAttribArray(mTriangleShader->getAttribute("vVertex"));
glVertexAttribPointer(mTriangleShader->getAttribute("vVertex"),3,GL_FLOAT,GL_FALSE,stride,0);
GL_CHECK_ERRORS;
//enable vertex attribute array for the color
glEnableVertexAttribArray(mTriangleShader->getAttribute("vColor"));
glVertexAttribPointer(mTriangleShader->getAttribute("vColor"),3,GL_FLOAT,GL_FALSE,stride,(const GLvoid*)offsetof(Vertex,color));
GL_CHECK_ERRORS;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(mIndices),&mIndices[0],GL_STATIC_DRAW);
glDisableVertexAttribArray(mTriangleShader->getAttribute("vVertex"));
glDisableVertexAttribArray(mTriangleShader->getAttribute("vColor"));
glBindVertexArray(0);
GL_CHECK_ERRORS;
mInitialized = true;
}
I think the issue lies here and I am examining it right now. Any hint from your end within the function will accelerate the process.
Thanks

*To copy to clipboard, switch view to plain text mode *

## Bookmarks