PDA

View Full Version : problem with texture



vbovio
01-10-2007, 08:24 AM
Hi,

I'm drawing a bitmap usiang a 2D textured quad, matching each pixels (no filtering), it works on my PC (windows), but for some reason, it does not work on a Mac, some of the bitmap pixels are missed or have an offset, any ideas ???, below is my code:

Thanks!


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, myViewportWidth, 0, myViewportHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

int x = 0;
int y = 0;
int w = nextPowerOfTwo(myBitmapWidth);
int h = nextPowerOfTwo(myBitmapHeight);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, myBitmapData);

glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2d(x, y);
glTexCoord2f(1.0f, 0.0f);
glVertex2d(x + w, y);
glTexCoord2f(1.0f, 1.0f);
glVertex2d(x + w, y + h);
glTexCoord2f(0.0f, 1.0f);
glVertex2d(x, y + h);
glEnd();

glDisable(GL_TEXTURE_2D);

glFlush();

sqrt[-1]
01-10-2007, 04:00 PM
Just guessing here, but your problem may be this:

int w = nextPowerOfTwo(myBitmapWidth);
int h = nextPowerOfTwo(myBitmapHeight);

If this changes the width/height of the bitmap, where do you rescale the bitmap data "myBitmapData"?

jide
01-11-2007, 01:23 AM
What kind of bitmap loading code do you have ? AFAIK MAC and PC do not have the same byte alignment. This might come from there, but it's only a vague guess.

vbovio
01-11-2007, 05:59 AM
sqrt[-1]: myBitmapData has the correct size of nextPowerOfTwo.
jide: it's not the same code for loading the bitmap, in fact the bitmap data is created at memory.

anyway, thanks for the replies

vbovio
01-11-2007, 07:20 AM
hey,
I found the issue,
thanks anyway.