Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


[Solved]Different draw with every launch


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 ScherzkeCks   Members   -  Reputation: 117

Like
0Likes
Like

Posted 15 August 2013 - 01:57 PM

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);

Attached Thumbnails

  • weird1.jpg
  • weird2.jpg

Edited by ScherzkeCks, 16 August 2013 - 04:53 AM.


Sponsor:

#2 Dave Hunt   Crossbones+   -  Reputation: 2479

Like
0Likes
Like

Posted 15 August 2013 - 02:17 PM

Did you ensure that you cleared the depth buffer before drawing?



#3 ScherzkeCks   Members   -  Reputation: 117

Like
0Likes
Like

Posted 15 August 2013 - 02:21 PM

Yes I call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); every frame



#4 BornToCode   Members   -  Reputation: 950

Like
0Likes
Like

Posted 15 August 2013 - 04:14 PM

Yes I call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); every frame

did you cal glEnable(GL_DEPTH_TEST); By default depht test is off.



#5 ScherzkeCks   Members   -  Reputation: 117

Like
0Likes
Like

Posted 16 August 2013 - 04:49 AM

Yes I do.

 

It was rendering just fine before when I had the geometry and such hard written into the code. Only thing I changed was loading from file (which works as confirmed by debugging) and I installed the OpenGL Profiler from Apple, which shouldn't interfere with my program, should it? Oh and I added the texture-loading. But I am not using the texture in the shader yet, I just give out plain red in the shader.

 

 

EDIT: I just found the bug. Shows again, that getting a night of sleep solves a lot of problems. I didn't initialize the variable indicesCount right that gets returned in currentObject->getIndicesCount()

 

Thank you all for your help!


Edited by ScherzkeCks, 16 August 2013 - 04:53 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS