Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualScherzkeCks

Posted 21 September 2013 - 04:45 AM

tried both, nothing changed.

 

Could it be some kind of wrong calls to change states? I will post the only other part of code that makes opengl calls after the creation of the window, maybe I am doing something wrong when switching from Model-Drawing to Text-Drawing.

 

This code gets called right before i call the drawText() function (This part works just fine)

void Render::renderObjects()
{

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUseProgram(programID);

	//Texture-Sampler Location
	GLuint textureSampler = glGetUniformLocation(programID,"myTextureSampler");

	GLint vpLocation = glGetUniformLocation(programID,"VP");
	glm::mat4 vp = GameManager::getSingleton()->getCamera()->getCameraMatrix();
	glUniformMatrix4fv(vpLocation,1,GL_FALSE,&vp[0][0]);

	GLint modelMatrixLocation = glGetUniformLocation(programID,"model");

	std::vector<RenderObject *> objectsToRender;

	objectsToRender = GameManager::getSingleton()->getROManager()->getObjectsToRender();



	for (int i = 0; i < objectsToRender.size(); ++i)
	{
		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 (RenderObjectException* e) {
				printf("%s\n", e->what());
				//TODO: remove from objectHandler and further error-Handling
				continue;
			}

			//Texture
			GLuint textureID;
			glGenTextures(1, &textureID);
			glBindTexture(GL_TEXTURE_2D, textureID);
			//glTexStorage2D(GL_TEXTURE_2D,4, GL_RGB, textureWidth, textureHeight);
			//glTexSubImage2D(GL_TEXTURE_2D,0,0,0,textureWidth,textureHeight,GL_BGR, GL_UNSIGNED_BYTE, textureData);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, textureData); // <- tutorial version but mutable

			glGenerateMipmap(GL_TEXTURE_2D);

			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
			//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

			currentObject->setTextureID(textureID);

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

			glBindVertexArray(0);


		}


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

		glBindVertexArray(0);
		

	}
	
}


#1ScherzkeCks

Posted 21 September 2013 - 04:44 AM

tried both, nothing changed.

 

Could it be some kind of wrong calls to change states? I will post the only other part of code that makes opengl calls after the creation of the window, maybe I am doing something wrong when switching from Model-Drawing to Text-Drawing.

 

This code gets called right before i call the drawText() function

void Render::renderObjects()
{

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUseProgram(programID);

	//Texture-Sampler Location
	GLuint textureSampler = glGetUniformLocation(programID,"myTextureSampler");

	GLint vpLocation = glGetUniformLocation(programID,"VP");
	glm::mat4 vp = GameManager::getSingleton()->getCamera()->getCameraMatrix();
	glUniformMatrix4fv(vpLocation,1,GL_FALSE,&vp[0][0]);

	GLint modelMatrixLocation = glGetUniformLocation(programID,"model");

	std::vector<RenderObject *> objectsToRender;

	objectsToRender = GameManager::getSingleton()->getROManager()->getObjectsToRender();



	for (int i = 0; i < objectsToRender.size(); ++i)
	{
		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 (RenderObjectException* e) {
				printf("%s\n", e->what());
				//TODO: remove from objectHandler and further error-Handling
				continue;
			}

			//Texture
			GLuint textureID;
			glGenTextures(1, &textureID);
			glBindTexture(GL_TEXTURE_2D, textureID);
			//glTexStorage2D(GL_TEXTURE_2D,4, GL_RGB, textureWidth, textureHeight);
			//glTexSubImage2D(GL_TEXTURE_2D,0,0,0,textureWidth,textureHeight,GL_BGR, GL_UNSIGNED_BYTE, textureData);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, textureData); // <- tutorial version but mutable

			glGenerateMipmap(GL_TEXTURE_2D);

			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
			//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

			currentObject->setTextureID(textureID);

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

			glBindVertexArray(0);


		}


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

		glBindVertexArray(0);
		

	}
	
}


PARTNERS