tags:

views:

126

answers:

2

I'm trying to generate textures like so:

#define checkImageWidth 64
#define checkImageHeight 64
static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
static GLubyte otherImage[checkImageHeight][checkImageWidth][4];

static GLuint texName[2];

void makeCheckImages(void)
{
    int i, j, c;

    for (i = 0; i < checkImageHeight; i++) {
        for (j = 0; j < checkImageWidth; j++) {
            c = ((((i&0x8)==0)^((j&0x8))==0))*255;
            checkImage[i][j][0] = (GLubyte) c;
            checkImage[i][j][1] = (GLubyte) c;
            checkImage[i][j][2] = (GLubyte) c;
            checkImage[i][j][3] = (GLubyte) 255;
            c = ((((i&0x10)==0)^((j&0x10))==0))*255;
            otherImage[i][j][0] = (GLubyte) c;
            otherImage[i][j][1] = (GLubyte) 0;
            otherImage[i][j][2] = (GLubyte) 0;
            otherImage[i][j][3] = (GLubyte) 255;
        }
    }
}
void init(void)
{    
    glClearColor (1.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);

    makeCheckImages();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glGenTextures(2, texName);
    glBindTexture(GL_TEXTURE_2D, texName[0]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
        GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
        GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
        checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
        checkImage);

    glBindTexture(GL_TEXTURE_2D, texName[1]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
        GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
        GL_NEAREST);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);   
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, 
        checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
        otherImage);
    glEnable(GL_TEXTURE_2D);

    engineGL.current.tex = texName[1];
}

But when I check the values of texName[0] and [1] they are both 0, I do not understand why, what am I doing wrong. Thanks.

A: 

Try calling glGetError. It should tell you in more detail what went wrong. In general, if an OpenGL function fails, the first thing you do should be to ask OpenGL why it failed. It knows, because it just tried to execute the function.

It's much harder for us to guess at what might have gone wrong.

jalf
I get error 1282, what's that?
Milo
Use `gluErrorString()` to find out. :) http://www.opengl.org/wiki/FAQ#glGetError_.28or_.22How_do_I_check_for_GL_errors.3F.29
jalf
"invalid operation"
Milo
The (documentation)[http://www.opengl.org/sdk/docs/man/xhtml/glGenTextures.xml] mentiones that "GL_INVALID_OPERATION is generated if glGenTextures is executed between the execution of glBegin and the corresponding execution of glEnd.". Does that help you?
jalf
Yea I had seen this but I don't do any sort of rendering before calling init() so im confused.
Milo
I completely removed my render code and it still does it.
Milo
A: 

You probably are calling glGenTextures before creating the OpenGL context, and that will generate a GL error. Don't try to create textures before you've initialized OpenGL.

Matias Valdenegro
Yes, that was 1 of my issues, I was also calling wglmakecurrent in my render loop which was causing trouble
Milo