Texture problems
I am having problems with my texture loading for OpenGL. It loads, but the alpha mask doesn't draw correctly and the colors get all mixed up. Below is my code.
If I use GL_BGRA_EXT and GL_UNSIGNED_INT_8_8_8_8_REV, then it doesn't even show my texture.
Code:
unsigned long LoadTextureImage(Str255 path)
{
FSSpec spec;
Rect natbounds;
GraphicsImportComponent gi;
ComponentResult cr;
void *buffer;
GWorldPtr gw;
unsigned long texture;
FSMakeFSSpec(0, 0, path, &spec);
GetGraphicsImporterForFile(&spec, &gi);
cr = GraphicsImportGetNaturalBounds(gi, &natbounds);
buffer = malloc(4 * natbounds.bottom * natbounds.right);
QTNewGWorldFromPtr(&gw, k32RGBAPixelFormat, &natbounds, NULL, NULL,
0, buffer, 4 * natbounds.right);
cr = GraphicsImportSetGWorld(gi, gw, NULL);
cr = GraphicsImportDraw(gi);
CloseComponent(gi);
glGenTextures(1, &texture); // Generate OpenGL texture IDs
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, texture); // Bind Our Texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, natbounds.right, natbounds.bottom, 0,
/*GL_BGRA_EXT*/GL_RGBA, /*GL_UNSIGNED_INT_8_8_8_8_REV*//*0x8035*/GL_UNSIGNED_BYTE, buffer);
return texture;
}
This looks like it was butchered from QTValuePak 
You should check that the QTVP sample works on your machine.
AFAIK, k32RGBAPixelFormat does not work on the Mac. It may work on Windows... You need to use k32ARGBPixelFormat on the Mac, at which point you do need GL_BGRA and GL_UNSIGNED_INT_8_8_8_8_REV. You're not checking the return from the QTNewGWorldFromPtr call, though, so it's hard to know if this is the problem.
Remember to free the buffer you've malloced in this function (unless you're using client storage).

You should check that the QTVP sample works on your machine.
AFAIK, k32RGBAPixelFormat does not work on the Mac. It may work on Windows... You need to use k32ARGBPixelFormat on the Mac, at which point you do need GL_BGRA and GL_UNSIGNED_INT_8_8_8_8_REV. You're not checking the return from the QTNewGWorldFromPtr call, though, so it's hard to know if this is the problem.
Remember to free the buffer you've malloced in this function (unless you're using client storage).
Quote:Originally posted by OneSadCookieYep, it was. A classic copy-and-paste job
This looks like it was butchered from QTValuePak

Quote:You should check that the QTVP sample works on your machine.It won't because the computer this is on runs Mac OS 9.
Quote:AFAIK, k32RGBAPixelFormat does not work on the Mac. It may work on Windows... You need to use k32ARGBPixelFormat on the Mac, at which point you do need GL_BGRA and GL_UNSIGNED_INT_8_8_8_8_REV. You're not checking the return from the QTNewGWorldFromPtr call, though, so it's hard to know if this is the problem.I tried changing it to k32ARGBPixelFormat and to GL_BGRA and GL_UNSIGNED_INT_8_8_8_8_REV but it still doesn't work
I slightly motified the code to check what QTNewGWorldFromPtr returns and it is fine.Perhaps something I should note: I don't actually use GL_BGRA and GL_UNSIGNED_INT_8_8_8_8_REV, I use the values they are defined as in gl.h and glext.h because I am too lazy to copy the headers from my Mac OS X computer. Should this really make a difference? Is there any reason a video card wouldn't support that stuff? I have use a Rage Pro.
Does your extensions string include GL_EXT_bgra and GL_APPLE_packed_pixel(s)?
Quote:Originally posted by OneSadCookieYes.
Does your extensions string include GL_EXT_bgra and GL_APPLE_packed_pixel(s)?
Perhaps I am binding the texture incorrectly.
Do I need to glEnable anything special?
Code:
glEnable(GL_BLEND); // Enable Blending
glDisable(GL_DEPTH_TEST);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.0f, 0.0f, -3.0f);
glRotatef(rotate, 1.0f, 0.0f, 0.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0);
glBindTexture(GL_TEXTURE_2D, testTexture);
glBegin(GL_QUADS);
//glColor3f(1.0f, 0.0f, 0.0f);
glNormal3f(0, 0, 1);
glTexCoord2f(0.0f, 0.0f); glVertex3d(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3d(1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, -1.0f); glVertex3d(1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, -1.0f); glVertex3d(0.0f, -1.0f, 0.0f);
glNormal3f(0, 0, -1);
glTexCoord2f(0.0f, 0.0f); glVertex3d(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3d(1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, -1.0f); glVertex3d(1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, -1.0f); glVertex3d(0.0f, -1.0f, 0.0f);
glEnd();
aglSwapBuffers(openGLContext);
GL_TEXTURE_2D...
Does your image have power-of-two width and height? If not, you'll need either to call gluBuild2DMipmaps rather than glTexImage2D, or you'll need to resize your image, either in an image editor, or programmatically.
Does your image have power-of-two width and height? If not, you'll need either to call gluBuild2DMipmaps rather than glTexImage2D, or you'll need to resize your image, either in an image editor, or programmatically.
Note also that using negative texture coordinates may not be what you expect, unless you do want repeating or have enabled clamping.
I have checked all of that stuff
The texture draws, just with really odd colors. The texture is a PNG with an alpha channel, if it matters... I am beginning to think the problem is my version of the OpenGL SDK. It is version 1.0
The texture draws, just with really odd colors. The texture is a PNG with an alpha channel, if it matters... I am beginning to think the problem is my version of the OpenGL SDK. It is version 1.0
Are any GL errors being reported?
How about you post a small section of the image. It's usually pretty easy to tell by looking at it.
Picture of the image or the image as it gets drawn in the program?
Both.
in the program. Outside the program:
Those links don't work (for, I think, obvious reasons
)
)
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES Texture Problems | jhbau1000 | 1 | 4,422 |
Jul 12, 2010 05:57 AM Last Post: Kezhaya |
|
| Texture mapping problems | thingythekid | 1 | 2,097 |
Aug 26, 2005 03:56 AM Last Post: OneSadCookie |
|
| Texture Problems | Sta7ic | 5 | 2,897 |
May 28, 2003 01:51 PM Last Post: OneSadCookie |
|

