Game Development Community

Basic OpenGL Rendering Control

by Dave Calabrese · in iTorque 2D · 04/29/2010 (10:25 pm) · 3 replies

I'm working on some basic OpenGL rendering in the engine, so in the renderObject call of an object that does render, I've commented out all but the parent::renderObject method and added in my own test code (the original code exists below this). I have the following:

void myNewObject::renderObject( const RectF& viewPort, const RectF& viewIntersection )
{
	glEnable(GL_TEXTURE_2D);
	
	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
	glColor3f(1.0f, 0.0f, 0.0f);	
	
	glBegin (GL_QUADS);
		glVertex2f(-0.25f, 0.25f);
		glVertex2f(-0.5f, -0.25f);
		glVertex2f(0.5f, -0.25f);
		glVertex2f(0.25f, 0.25f);
	glEnd();
	
	glDisable( GL_TEXTURE_2D );
	
	Parent::renderObject( viewPort, viewIntersection ); // Always use for Debug Support!
};

However, when trying this, nothing renders to the screen. If I return the original code, things render fine. I'm a bit confused as to why nothing is rendering to the screen, since this is the same place that the normal rendering occurs, so I must be doing something wrong. :)

Any help would be greatly appreciated - wrapping my head around OpenGL here, got some great books and everything and now I'm just trying to get it all working properly in Torque!

#1
04/30/2010 (12:19 am)
I think that Torque2D for iPhone uses openGL ES and not openGL (because iPhone uses openGL ES).

glBegin() doesn't exist any more in openGL ES.

Perhaps that could be the start of your answer?

Nicolas Buquet
www.buquet-net.com/cv/
#2
04/30/2010 (2:33 am)
Just to confirm: thats right

OpenGL ES has no immediate mode rendering
#3
04/30/2010 (10:03 am)
Thanks for the pointers, guys. I got it working. Here's the basic OpenGL ES code I'm now using to render a simple shape:

GLfloat square[] = 
	{
		-20.0, 20.0,
		20.0, 20.0,
		0.25, 0.75,
		0.75, 0.75
    };
	
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glVertexPointer(2, GL_FLOAT, 0, square);	
	
	glEnableClientState(GL_VERTEX_ARRAY);
	
	glClear(GL_COLOR_BUFFER_BIT);
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);