Generating Textures

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_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

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

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

…should fix your problem. It’s a common issue.

  • Matt

now where would you add that pixelstorei? gotta give specific info pls.

well anywhere before the last line glTexImage2D(…) should be ok