program generated 1D texture

I’m trying to create a simple 1D texture of different colours to put over an object as simple colour bands.

So I tried to set it up like this;

GLubyte Texture4[4][3] =

  { 0x00, 0x00, 0xa0 },   // Dark Blue
  { 0x00, 0x00, 0xff },   // Blue
  { 0x00, 0xff, 0x00 },   // Green
  { 0xff, 0x00, 0x00 }   // Red


(other paremeter settings in here…)

glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 4, 0, GL_RGB , GL_UNSIGNED_BYTE, Texture4);

Now this partly works the dark blue, blue and the green colour bands show up just fine, but for some reason the red is just black.

It’s as if the red RGB component gets completely ignored, but all the others work just fine.

Any ideas?

Thanks all.

The input array should be flat: “GLubyte Texture4[12]” instead of “GLubyte Texture4[4][3]”.

Statically-allocated arrays will be stored in contiguous memory, so I don’t think the multidimensionality is an issue.

  • Chris

It could be the pixel alignment. I think by default the driver expects texel data to be aligned on word (4 byte) boundaries. Your data is RGB, so you’d need to specify byte alignment with something like:


But I’m not certain.

  • Chris

That’s the way I have it set up.

Here’s image of it, notice the top is supposed to be Red but it looks black and the other colours worked.

How are you assigning texture coordinates? Are you clamping them to the texture edge? The man page for glTexImage1D indicates that the OpenGL specification guarantees no textures with dimension less than 64. You might try replicating each color 16 times.

  • Chris

void glTexImage1D

GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLint border,
GLenum format,
GLenum type,
const GLvoid * data



Specifies the width of the texture image including the border if any. If the GL version does not support non-power-of-two sizes, this value must be 2^n+2 (border) for some integer n. All implementations support texture images that are at least 64 texels wide. The height of the 1D texture image is 1.

Thanks I just read that in the man page, but this is talking about texels not pixels.

I don’t think this means that my 1D texture (line) has to be 64 pixels wide, but I’m going to try that anyhow as nothing else seems to be working.

I might end up having to use a 2D image texture after all, which I was hoping not to as it complicated everything :frowning:

Wild guess, but i always suspect this thing when i see black output from texture (only partially black output suggests that its not the thing but anyways …).
Could you try doing for the texture:


Also, putting some colours in other components could help debugging.
Also, you could try glintercept to see if texture is uploaded correctly.

Maybe something to do with wrapping mode ? Try setting it to GL_CLAMP_TO_EDGE.

Thanks to all the replies.

I tried each suggestion but the problem persists.

I’m doing with with the FLTK library on Linux.

It’s possible there’s some bug in the FLTK GL windowing code.

Maybe the video card on this laptop is the problem.

So I’m when I get the chance I’ll compile on my other computer with the better video. (this will be awhile since I’m away from home and only can use the laptop for now)

I’ve started to create a GTK+ version of the program to see if this changes anything.

When I get time I’ll try a simple test with GLX only.

Thanks all.