Jump to content
  • Advertisement
Sign in to follow this  
GuyZ

OpenGL glDrawElements - Nothing gets rendered

This topic is 3072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey. I'm having trouble rendering a model in OpenGL ES 1.0, the platform is Android (Java bindings for OpenGL ES/JSR 239). The screen gets cleared with the clear color, but no geometry can be seen. Trying to do the same with glDrawArrays worked. Parts of code: Init:
        float lightAmbient[] = new float[] { 0.2f, 0.2f, 0.2f, 1 };
	float lightDiffuse[] = new float[] { 1, 1, 1, 1 };
	float[] lightPos = new float[] { 1, 1, 1, 1 };
	
	gl.glViewport(0, 0, view.getWidth(), view.getHeight());
	gl.glMatrixMode(GL10.GL_PROJECTION);
	gl.glLoadIdentity();
	float ratio = (float) view.getWidth() / view.getHeight();
	GLU.gluPerspective(gl, 45.0f, ratio, 1, 100f);

	
	gl.glEnable(GL10.GL_DEPTH_TEST);
	gl.glDepthFunc(GL10.GL_LEQUAL);
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	
	
	gl.glEnable(GL10.GL_LIGHTING);
	gl.glEnable(GL10.GL_LIGHT0);
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0);
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0);
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
	
	float matAmbient[] = new float[] { 1, 1, 1, 1 };
	float matDiffuse[] = new float[] { 1, 1, 1, 1 };
	gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0);
	gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0);
	
	gl.glClearColor(0, 1, 0, 1);

Rendering:
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	
	gl.glMatrixMode(GL10.GL_MODELVIEW);
	gl.glLoadIdentity();
	gl.glTranslatef(0, 0, -3.0f);
	
	cube.draw(gl);

cube's draw() function:
        gl.glFrontFace(GL10.GL_CW);
	
	gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);

	
	gl.glColor4x(1, 0, 0, 1);
	
	gl.glDrawElements(GL10.GL_TRIANGLES, 36 , 
		GL10.GL_UNSIGNED_SHORT, 
		mIndexBuffer);

36 is the number of indices. Am I doing something wrong with the camera setup, or am I missing something here?

Share this post


Link to post
Share on other sites
Advertisement
Nvm - I found the error, I had model's vertices as ints, but used the Float version of glTranslate.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!