Sign in to follow this  
loudking

cannot texture from .RGB files

Recommended Posts

loudking    122
I am now trying to make textures from a RGB file, but unable to do. can anybody give a hand? [code] typedef struct _TK_RGBImageRec { int sizeX, sizeY, components; unsigned int format; unsigned char *data; } RGBImage; void texture() {RGBImage *textures; textures = LoadRGB(textureFile); glGenTextures(1, textures->data); glBindTexture(GL_TEXTURE_2D, textures->data); glTexImage2D(GL_TEXTURE_2D, 0, 3, textures->sizeX, textures->sizeY,0,GL_RGB, textures->format, textures->data); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_CLAMP, GL_REPEAT); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } [\code] GL_TEXTURE_2D has already been enabled, using glEnable(GL_TEXTURE_2D); coordinate of texture has also been set: [code] glNormal3fv(pyramidNormal[4]); glBegin(GL_QUADS); glColor3fv(color[4]); glTexCoord2f(0.0, 0.0); glVertex3fv(pyramidVertex[1]); glTexCoord2f(1.0, 0.0); glVertex3fv(pyramidVertex[2]); glTexCoord2f(1.0, 1.0); glVertex3fv(pyramidVertex[3]); glTexCoord2f(0.0, 1.0); glVertex3fv(pyramidVertex[4]); glEnd(); [\code] I really cannot find what reason it is.

Share this post


Link to post
Share on other sites
Brother Bob    10344
I'm going to assume LoadRGB is working correct.

There are issues with your code though. You only set the magnification filter, but leaves the minification filter to default. Default filter requires a complete mipmap set, but you're only uploading the base level. Set minification filter to GL_LINEAR or GL_NEAREST too.

GL_CLAMP is not a valid parmeter name for glTexParameter. If you want repeating behaviour, the parmeter names are GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T.

Your call to glGenTextures is wrong. glGenTextures generates a texture ID and stores the value where the last parameter points. You pass the image data pointer, which means OpenGL will overwrite the first pixel with the generated texture ID. You should pass the address or a GLuint which will receive the texture ID.

And related to last point, glBindTexture should take the texture ID generated by glGenTextures, not a pointer to the image data.

If you need the call to glPixelStore, you should at least set it before calling glTexImage. After, it will have no effect, as the data is already incorrectly uploaded.


GLuint ID;

glGenTextures(1, &ID);
glBindTexture(GL_TEXTURE_2D, ID);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexImage2D(GL_TEXTURE_2D, 0, 3, textures->sizeX, textures->sizeY, 0, GL_RGB, textures->format, textures->data);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

Share this post


Link to post
Share on other sites
Seroja    280

typedef struct _TK_RGBImageRec
{
int sizeX,
sizeY,
components;
unsigned int format;
unsigned char *data;
} RGBImage;

void texture()
{
RGBImage *textures; // Your texture container
textures = LoadRGB(textureFile); // This loads texture from file, right?

// Wrong
glGenTextures(1, textures->data);
glBindTexture(GL_TEXTURE_2D, textures->data);
/* glGenTextures allocates the amount (1) of textures to be
assigned using glBindTexture, and stores their indexes in the array
you pass to it. Pass the index, not the texture data.
glBindTexture should then take the index, not the data */

// Try this
GLuint TexIndex;
glGenTextures(1, &TexIndex);
glBindTexture(GL_TEXTURE_2D, TexIndex);

// I think that glPixelStore, glTexParameter etc. should be called
// Before glTexImage 2D. Not sure though.
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_CLAMP, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, textures->sizeX,
textures->sizeY,0,GL_RGB, textures->format, textures->data);
}

Share this post


Link to post
Share on other sites
Brother Bob    10344
Quote:
Original post by Seroja

// I think that glPixelStore, glTexParameter etc. should be called
// Before glTexImage 2D. Not sure though.


glPixelStore must be called before glTexImage, as it affects how the data is read. glTexParameter though can be called at any time, as long as the correct texture ID is bound.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this