Problems with SimplestObject
by Mehmet Kizil · in Torque Game Engine · 08/31/2005 (8:53 pm) · 4 replies
Hey people, short question. I'm trying to make a translucent box using a modified SimplestObject. This is what i've done to modify the SimplestObject.cc
In between the first PushMatrix(); in the renderObject method i've added this:
And when the primitives are being drawn after glBegin(GL_TRIANGLES);
However the error catching on line 40 is getting pulled up whenever I add SimplestObject to the mission. Could someone explain this error? This is the relevent section of code catching it:
In between the first PushMatrix(); in the renderObject method i've added this:
// Setup our rendering state (alpha blending). glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
And when the primitives are being drawn after glBegin(GL_TRIANGLES);
glColor4f(0.2,1.0,0.6,0.5);
However the error catching on line 40 is getting pulled up whenever I add SimplestObject to the mission. Could someone explain this error? This is the relevent section of code catching it:
// Check we have restored Canonical State. AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on exit");
#2
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
just before I draw the primitives (a box)
then disable it right after I draw it
it's still nailing me on the "Error, GL not in canonical state on exit". I still cant see where I have changed the state without switching it back :(
I'm sure its not good to post the WHOLE code here, so i'll just do what I have done.
09/01/2005 (5:41 am)
Yes, what I have been trying to do is set up the glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
just before I draw the primitives (a box)
then disable it right after I draw it
it's still nailing me on the "Error, GL not in canonical state on exit". I still cant see where I have changed the state without switching it back :(
I'm sure its not good to post the WHOLE code here, so i'll just do what I have done.
void SimplestObject::renderObject(SceneState* state, SceneRenderImage*)
{
<snip>
// Save Projection Matrix so we can restore Canonical state at exit.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
// Save Viewport so we can restore Canonical state at exit.
dglGetViewport(&viewport);
<snip>
state->setupBaseProjection();
// Save ModelView Matrix so we can restore Canonical state at exit.
glPushMatrix();
// Transform by the objects' transform e.g move it.
dglMultMatrix(&getTransform());
glScalef(mObjScale.x, mObjScale.y, mObjScale.z);
bool debugCollision = false;
// Setup our rendering state (alpha blending).
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Enable Texturing.
glEnable(GL_TEXTURE_2D);
// I separated out the actual render function to make this a little cleaner
render();
glDisable(GL_BLEND);
// Restore our canonical matrix state.
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
// Restore our canonical viewport state.
dglSetViewport(viewport);
// Check we have restored Canonical State.
AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on exit");
}
bool SimplestObject::render(void)
{
// Render a standard OpenGL beginner cube
glBegin(GL_TRIANGLES);
// Set Colour/Alpha.
glColor4f(0.2,1.0,0.6,0.5);
glVertex3f(mPoints[0].x, mPoints[0].y, mPoints[0].z);
glVertex3f(mPoints[3].x, mPoints[3].y, mPoints[3].z);
glVertex3f(mPoints[2].x, mPoints[2].y, mPoints[2].z);
glVertex3f(mPoints[0].x, mPoints[0].y, mPoints[0].z);
glVertex3f(mPoints[2].x, mPoints[2].y, mPoints[2].z);
glVertex3f(mPoints[1].x, mPoints[1].y, mPoints[1].z);
glVertex3f(mPoints[4].x, mPoints[4].y, mPoints[4].z);
glVertex3f(mPoints[5].x, mPoints[5].y, mPoints[5].z);
glVertex3f(mPoints[6].x, mPoints[6].y, mPoints[6].z);
glVertex3f(mPoints[4].x, mPoints[4].y, mPoints[4].z);
glVertex3f(mPoints[6].x, mPoints[6].y, mPoints[6].z);
glVertex3f(mPoints[7].x, mPoints[7].y, mPoints[7].z);
// Set Colour/Alpha.
glColor4f(0.2,1.0,0.6,0.5);
glVertex3f(mPoints[0].x, mPoints[0].y, mPoints[0].z);
glVertex3f(mPoints[4].x, mPoints[4].y, mPoints[4].z);
glVertex3f(mPoints[7].x, mPoints[7].y, mPoints[7].z);
glVertex3f(mPoints[0].x, mPoints[0].y, mPoints[0].z);
glVertex3f(mPoints[7].x, mPoints[7].y, mPoints[7].z);
glVertex3f(mPoints[3].x, mPoints[3].y, mPoints[3].z);
glVertex3f(mPoints[1].x, mPoints[1].y, mPoints[1].z);
glVertex3f(mPoints[2].x, mPoints[2].y, mPoints[2].z);
glVertex3f(mPoints[6].x, mPoints[6].y, mPoints[6].z);
glVertex3f(mPoints[1].x, mPoints[1].y, mPoints[1].z);
glVertex3f(mPoints[6].x, mPoints[6].y, mPoints[6].z);
glVertex3f(mPoints[5].x, mPoints[5].y, mPoints[5].z);
// Set Colour/Alpha.
glColor4f(0.2,1.0,0.6,0.5);
<snip -you get the idea ;)>
glEnd();
return true;
}
#3
09/01/2005 (5:50 am)
*Note - this has been fixed. for those that want to know, I didnt revert the glEnable(GL_TEXTURE_2D); back to its original state
#4
09/01/2005 (10:19 am)
Glad you got this fixed! :)
Associate Kyle Carter