PDA

View Full Version : Background Changing Colour and Images Messed Up



Salbris
07-10-2009, 04:34 PM
I've got two problems with OpenGL right now.

1. A background colour I setup changes colour when nearly everytime the window is redraw.

http://s377.photobucket.com/albums/oo220/salbrismind/OpenGL/

I set the colour as beige but it doesn't stay for long and gets replaced by darker colours. I have no code setup to setup these colours, so my guess is OpenGL is darkening it, I'm not sure why though.


2. If you look in the same images: http://s377.photobucket.com/albums/oo220/salbrismind/OpenGL/

You'll notice a button I made at the top with the word "Wall" on it. The image doesn't load properly it has some weird colouration problems on it. If you look closely parts of the top, side, and of the letters has a rainbow covering it. The other image below were loaded with the same functions and had no problem. Does anyone know why this is happening?


Thanks in Advance.

ZbuffeR
07-10-2009, 05:11 PM
1. no idea. do you play with blending ? what is your clearcolor ?
2. depends on the image format, color depth, etc. Probably more to do with you loading routine than opengl code.

Salbris
07-10-2009, 08:22 PM
1. no idea. do you play with blending ? what is your clearcolor ?
2. depends on the image format, color depth, etc. Probably more to do with you loading routine than opengl code.


1. I haven't played with blending, no. My clearColour?

2. I've been using some code from a tutorial I've been following, it loads a bmp image with a 24bit colour depth. But it has worked flawlessly until now.

Salbris
07-11-2009, 12:00 PM
Okay I started using the glClearColor function, but it still does not fix my problem.

ZbuffeR
07-11-2009, 12:34 PM
Hard to help without more info.

Backup your current code, then remove things little by little until the problem disappear. You will probably understand yourself how to fix it then. If it still puzzles you, post the simplest compilable code that still has the bug.

Start to chase the background problem first.

Salbris
07-11-2009, 01:52 PM
Hard to help without more info.

Backup your current code, then remove things little by little until the problem disappear. You will probably understand yourself how to fix it then. If it still puzzles you, post the simplest compilable code that still has the bug.

Start to chase the background problem first.

Well I narrowed my code to here:



if (!buttonList.isEmpty())
{
ButtonNode *seek = buttonList.first;

while (seek != 0)
{
seek->button->draw();
seek = seek->next;
}
}


button->draw(); is this:


void Button::draw() const
{
int textureId;
switch (state)
{
case NORMAL:
textureId = normalTexture;
break;

case MOUSE_OVER:
textureId = mouseOverTexture;
break;

case ACTIVE:
textureId = activeTexture;
break;

default:
textureId = normalTexture;
}


glPushMatrix();
GLAddons::glTranslateVector(Vectorf(positionX, positionY, 0));

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Colours::White.setAsCurrent();
glBegin(GL_QUADS);

glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(width, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(width, height);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, height);

glDisable(GL_TEXTURE_2D);
glEnd();

glPopMatrix();
}


Any idea what's causing it?


The same thing occurs in another function where I draw a texture:


void Environment::drawTile(char tile, unsigned int x, unsigned int y) const
{
unsigned int textureId = tileToTexture(tile);

glPushMatrix();

//Set the position
GLAddons::glTranslateVector(grid.getPosition(x, y));

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Colours::White.setAsCurrent();
glBegin(GL_QUADS);

glNormal3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(Avatar::AvatarSize, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(Avatar::AvatarSize,Avatar::AvatarSize);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, Avatar::AvatarSize);

glDisable(GL_TEXTURE_2D);
glEnd();

glPopMatrix();
}

ZbuffeR
07-11-2009, 02:15 PM
You are on the background color problem, right ?
How do you draw it ?

Salbris
07-11-2009, 02:16 PM
You are on the background color problem, right ?
How do you draw it ?



glPushMatrix();
GLAddons::glTranslateVector(BACKGROUND_POSITION);

glBegin(GL_QUADS);
Colours::Beige.setAsCurrent();

glVertex3f(-800, -800, 0);
glVertex3f(-800, mScreenHeight + 800, 0);
glVertex3f(mScreenWidth + 800, mScreenHeight + 800, 0);
glVertex3f(mScreenWidth + 800, -800, 0);

glEnd();

glPopMatrix();


setAsCurrent(); calls glColor3f