• Advertisement
Sign in to follow this  

Wierd Rendering Effects

This topic is 3872 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

Ive got a game where youre in a maze and you have to find a key. I set the text color to glColor3f(1.0f,1.0f,1.0f); but when it renders everything renders a lot darker than it should be. When you find the key everything renders its normal color. Once you have the key it draws a picture of the key at the top of the screen. I cant figure out whats wrong. Please could you help me eg code: if(gotkey == false) { //drawkey } else { //draw keypic at top } thats all that changes between finding the key(all text and images are dark and not the color they should be until the key is found)

Share this post


Link to post
Share on other sites
Advertisement
There's probably a change in render states somewhere in the call to draw the picture. Figure out exactly what's going on in the process of drawing your image, and find out if any internal rendering states are being changed to make rendering a picture possible. If there are changes, figure out what the changes do and try to set them yourself so Text/etc always renders properly.

Share this post


Link to post
Share on other sites
From what ive noticed all that changes is switching from perspective to orthographic projection between rendering the text and picture instead of the model of the key. I still cant figure out whats going wrong

Share this post


Link to post
Share on other sites
Could you post your rendering code for the key model and picture as well as the portion where you are switching the render mode? It really seems to be a matter of subtle state changes. For example there might be a color that is changed by the model which affects the rest of the scene.

Please provide us some code so that we can help you with analyzing.

Share this post


Link to post
Share on other sites
This is my view setup:
GLvoid GL::Init()
{
if (height==0)height=1;
glViewport(0,0,width,height); // Reset The Current Viewport
glDeleteLists(g_persp,1);
glDeleteLists(g_ortho,1);
g_persp = glGenLists(1);
g_ortho = glGenLists(1);
glNewList(g_persp,GL_COMPILE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,5000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEndList();
glNewList(g_ortho,GL_COMPILE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble) 800.0f, 0.0, (GLdouble) 600.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEndList();
objCamera.mWindowWidth = width;
objCamera.mWindowHeight = height;
}
This is the key rendering code:
void C3dsLoader::Render_3ds()
{

for(int i = 0; i < m3DModel.numOfObjects; i++)
{

if(m3DModel.pObject.size() <= 0) break;

t3DObject *pObject = &m3DModel.pObject[i];

if(pObject->bHasTexture)
{
glColor3ub(255, 255, 255);

glBindTexture(GL_TEXTURE_2D, TextureArray3ds[pObject->materialID]);
}
else
{
glColor3ub(255, 255, 255);
}

glBegin(GL_TRIANGLES);

for(int j = 0; j < pObject->numOfFaces; j++)
{

for(int whichVertex = 0; whichVertex < 3; whichVertex++)
{
int index = pObject->pFaces[j].vertIndex[whichVertex];

glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);

if(pObject->bHasTexture) {

if(pObject->pTexVerts) {
glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
}
} else {

if(m3DModel.pMaterials.size() < pObject->materialID)
{
BYTE *pColor = m3DModel.pMaterials[pObject->materialID].color;

glColor3ub(pColor[0], pColor[1], pColor[2]);
}
}

glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
}
}

glEnd();
}

}

this is the picture rendering:
if(gotkey == false)
{
glPushMatrix();
glTranslatef(54.0f,-5.0f,-55.0f);
glScalef(4.0f,4.0f,4.0f);
Key.Render_3ds();
glPopMatrix();
}
else
{
glCallList(g_ortho);
if(!fullscreen)glRasterPos2i(645,500);
else glRasterPos2i(645,535);
glDrawPixels(56,56,GL_RGB,GL_UNSIGNED_BYTE,(GLvoid*)Keypic);
glCallList(g_persp);
}

PLease could someone help

Share this post


Link to post
Share on other sites
i don't see if you enable it but i'd try to disable GL_LIGHTING, GL_BLEND,

Share this post


Link to post
Share on other sites
My guess would be something to do with your textures, I suspect that when you render something that isn't supposed to be textured it's using the last texture assigned.

Share this post


Link to post
Share on other sites
Thanks for all the help guys. Turns out it was a texture problem. It was blending the last texture loaded in with everything, changing the color

Share this post


Link to post
Share on other sites
Oh, too late [smile].

Just for clarification:

Suppose you have a texture which has a dark pixel at position 0. You render the textured object and afterwards render a nob-textured object. If you didn't disable texturing OpenGL will try to texture that object, too. Depending on your settings that could mean modulating the object's color with the texture. However, since the object should not be textured you didn't specify any texture coordinates, so OpenGL is likely to assume 0/0 for every pixel. Thus each pixel will be modulated with the darker texture color.

Share this post


Link to post
Share on other sites
Thanks Lord_Evil...

It seems what you are saying is exactly what was happening. The way i fixed it was to draw an object out of view and bind a pure white texture to it but I'm going to do disable texturing after calls to drawing models and see what happens

Share this post


Link to post
Share on other sites
Quote:
Original post by Emerican_360
Thanks Lord_Evil...

It seems what you are saying is exactly what was happening. The way i fixed it was to draw an object out of view and bind a pure white texture to it but I'm going to do disable texturing after calls to drawing models and see what happens


Hi

Sorry to bother you, but I have a similar problem. I already make a thread about it, this is the link:
http://www.gamedev.net/community/forums/topic.asp?topic_id=451801

Can you please be little more specific about your solution? Perhaps it will works to me too.

Thanks a lot.

Share this post


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

  • Advertisement