Jump to content

  • Log In with Google      Sign In   
  • Create Account

Can't draw polygons in iOS


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
3 replies to this topic

#1 NSDuo   Members   -  Reputation: 270

Like
0Likes
Like

Posted 31 May 2014 - 01:09 PM

 I'm trying to draw a simple polygon in iOS, but I always end up with a blank glClearColor'ed screen. When I compile the cross-platform code for the desktop, it works.

 

I've implemented my own matrix functions, set up the shaders properly with "lowp, mediump" appearing only in the mobile version. I don't even get errors with the shaders or OpenGL on desktop or mobile.

 

From this I've guessed that the problem must be in my rendering code, but I copied the code from a tutorial project that does work and I still can't get anything to render.

 

Here is my sprite rendering code

//Mobile Renderer
		static const float POSITION[ 8 ] = {
			0.0f, 0.0f, // Down left (pivot point)
			1.0f, 0.0f, // Up left
			0.0f, 1.0f, // Down right
			1.0f, 1.0f  // Up right
		};
		
		glUseProgram(Graphics->currentShader->getProgram());
		
		//Graphics->setMatrixMode(SINNCA_MODELVIEW_MATRIX);
		//Graphics->loadIdentity();
		//Graphics->scale(100.0f, 100.0f, 0.0f);
		
		GLint att = glGetAttribLocation(Graphics->currentShader->getProgram(), "position");
		// returns 0, so that was successful

		glEnableVertexAttribArray(att);
		glVertexAttribPointer(att, 2, GL_FLOAT, GL_FALSE, 0, POSITION);
		glUniformMatrix4fv(Graphics->currentShader->uniformMVMatrix, 1, GL_FALSE, (float*)Graphics->getModelMatrix()); // also works

		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		
		/*//Desktop Renderer. With the matrices and shader this works perfectly
		glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
		
		glBufferSubData(GL_ARRAY_BUFFER, 0, 4 * sizeof(vertex), vertices);
		glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)offsetof(vertex, texco));
		glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)offsetof(vertex, position));
		
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBuffer);
		
		glUniformMatrix4fv(Graphics->currentShader->uniformMVMatrix, 1, GL_FALSE, (float*)Graphics->getModelMatrix());
		glEnableVertexAttribArray(Graphics->currentShader->attributePosition);
		glVertexAttribPointer(Graphics->currentShader->attributePosition, 2, GL_FLOAT, GL_FALSE, 0, 0);
		
		glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, NULL);
		//glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		 */

Is there something wrong with the code or am I forgetting another step?


Macbook Pro 2.66Ghz dual core, 4GB ram, 512MB vram, MacOSX 9.1, Windows 8.1
Xcode 5.0.2, C++, lua


Sponsor:

#2 Stainless   Members   -  Reputation: 1070

Like
0Likes
Like

Posted 01 June 2014 - 03:15 AM

Have you setup a texture?

 

Have you done a glColor4f(1,1,1,1);

 

When I get a problem of this type (works on X , doesn't work on Y) I start by looking at any opengl states that could produce this result.

 

Graphics drivers have different start states. On one device textures might be enabled by default, on others disabled by default. The same applies to all other opengl states.

 

So check face culling, check depth buffer, check textures, check colour, check any state flag you can think of.

 

It can be a real pain tracking down which one is causing the problem, but it's worthwhile knowing for the future.



#3 NSDuo   Members   -  Reputation: 270

Like
0Likes
Like

Posted 01 June 2014 - 07:43 AM

I disabled all of the graphics states and got it to work, thank you!

 

Now I can figure out which one was causing the problem (right after I get some sleep first).


Macbook Pro 2.66Ghz dual core, 4GB ram, 512MB vram, MacOSX 9.1, Windows 8.1
Xcode 5.0.2, C++, lua


#4 Stainless   Members   -  Reputation: 1070

Like
0Likes
Like

Posted 02 June 2014 - 03:26 AM

Glad to help.. "Sleep is a weapon"  Robert Ludlum






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