Problem with texture on Mac

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);
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();

Please post the relevant bits of the code if you want help. Hint: the bit where you actually load the bitmap is most likely to be wrong. Also, tell us whether you’re using a PowerPC or an Intel Mac.

Take a look at the OpenGL Correctness tips. The part from “if exact two-dimensional rasterization is desired…” This may be your problem.

http://fly.cc.fer.hr/~unreal/theredbook/appendixh.html

ie: use x+0.375f and x+0.375f+w-1 instead of x and x+w

hey guys thanks!

“Pop N Fresh”: I checked that URL and I did that translation and it worked…!!

also, I found that in other parts of my code gluProject was returning me a 2D point with fractions, that also leads to problem, I just did round and worked too,

many tahnks for the help!.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.