PDA

View Full Version : Generating Textures



DrakanFyr
11-13-2000, 05:02 PM
I am trying to build a 2x2 texture that is a solid color. This is the function I have been trying to use but it doesn't work. If I make the texture GL_RGBA and add a 4th alpha bit, it works fine. So what's up?


void GLTexture::BuildColorTexture(unsigned char r, unsigned char g, unsigned char b)
{
unsigned char data[12];

// Store the data
for (int i = 0; i < 12; i+=3)
{
data[i] = r;
data[i+1] = g;
data[i+2] = b;
}

// Generate the OpenGL texture id
glGenTextures(1, &texture[0]);

// Bind this texture to its id
glBindTexture(GL_TEXTURE_2D, texture[0]);

// Use linear filters
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

// Generate the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
}

mcraighead
11-13-2000, 05:09 PM
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

...should fix your problem. It's a common issue.

- Matt

x0skelet0n
11-14-2000, 09:41 AM
now where would you add that pixelstorei? gotta give specific info pls.

zed
11-14-2000, 11:34 AM
well anywhere before the last line glTexImage2D(..) should be ok