Hi,
can somebody explain to me why the same Program just launched over and over again results in different drawing output?
The Data is static so it doesn't change. I attached two sampleImages that show a partly rendered Sphere where there should be a full sphere
The code show the actual Code to draw the sphere, the if(vertexArrayObjectName == 0) only get called once and the data returned in currentObject->getData() is always the same.
Thanks so much in advance
Stefan
RenderObject *currentObject = objectsToRender.at(i);
GLuint vertexArrayObjectName = currentObject->getVertexArrayName();
if (vertexArrayObjectName == 0)
{
//Create vertexarrayobject and buffers etc.
GLfloat* vertices = NULL;
GLfloat* normals = NULL;
GLuint* indices = NULL;
GLfloat* uvCoordinates = NULL;
int verticesCount;
int indicesCount;
short textureWidth, textureHeight;
char* textureData = NULL;
try {
currentObject->getData(&vertices, &normals, &indices, &uvCoordinates, &verticesCount, &indicesCount, &textureWidth, &textureHeight, &textureData);
}
catch (ExceptionFile* e) {
printf("%s\n", e->what());
//TODO: remove from objectHandler and further error-Handling
continue;
}
//creating vertexarray
glGenVertexArrays(1,&vertexArrayObjectName);
glBindVertexArray(vertexArrayObjectName);
currentObject->setVertexArrayName(vertexArrayObjectName);
//create the buffers belonging to this vertexarray
GLuint vboId;
glGenBuffers(1,&vboId);
glBindBuffer(GL_ARRAY_BUFFER,vboId);
glBufferData(GL_ARRAY_BUFFER,verticesCount * sizeof(GLfloat) * 4,vertices, GL_STATIC_DRAW);
glVertexAttribPointer(RENDER_POSITION_LOCATION,4,GL_FLOAT,GL_FALSE,0,0);
glEnableVertexAttribArray(RENDER_POSITION_LOCATION);
//normalBuffer
GLuint normalBuffer;
glGenBuffers(1,&normalBuffer);
glBindBuffer(GL_ARRAY_BUFFER,normalBuffer);
glBufferData(GL_ARRAY_BUFFER, verticesCount * 4 * sizeof(GLfloat),normals, GL_STATIC_DRAW);
glVertexAttribPointer(RENDER_NORMALS_LOCATION,4,GL_FLOAT,GL_FALSE,0,NULL);
glEnableVertexAttribArray(RENDER_NORMALS_LOCATION);
//uvCoordinatesBuffer
GLuint uvCoordinatesID;
glGenBuffers(1,&uvCoordinatesID);
glBindBuffer(GL_ARRAY_BUFFER,uvCoordinatesID);
glBufferData(GL_ARRAY_BUFFER,verticesCount * sizeof(GLfloat) * 2,uvCoordinates,GL_STATIC_DRAW);
glVertexAttribPointer(RENDER_UV_LOCATION,2,GL_FLOAT,GL_FALSE,0,0);
glEnableVertexAttribArray(RENDER_UV_LOCATION);
GLuint indicesID;
glGenBuffers(1,&indicesID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,indicesCount * sizeof(GLuint),indices,GL_STATIC_DRAW);
//Texture
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, textureData);
currentObject->setTextureID(textureID);
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,currentObject->getTextureID());
glUniform1i(textureSampler,0);
glm::mat4 modelMatrix = currentObject->getModelMatrix();
glUniformMatrix4fv(modelMatrixLocation,1,GL_FALSE,&modelMatrix[0][0]);
glBindVertexArray(vertexArrayObjectName);
glDrawElements(GL_TRIANGLES,currentObject->getIndicesCount(),GL_UNSIGNED_INT,0);