Learning Excerise Ken's Labyrinth


Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,518
Location
Detroit, Michigan
Website
Visit site
I think i know EGL ok, not that its too hard to understand. Id like to learn opengles better, I know some basics with some of the other things ive messed around with. This time i want to give porting an opengl application to opengles. Ive come across ken's labyrinth and i think it might be a good starting point.

With a quick look at it uses sdl, gl, glu libraries. Im going to start with keeping sdl 1.2, but i may have to switch since im going to use glues (which might need SDL 1.3)
So using glues and sdl, just converting the gl to gles is needed.
Im hoping some of you chime in and point me in the right direction.

2 big things ive see so far:

Code:
glDrawBuffer(GL_FRONT);
glDrawBuffer(GL_BACK);

not sure if these are even needed

Code:
#ifndef OPENGLES    
    glBegin(GL_QUADS);
    glColor3f(redfactor,greenfactor,bluefactor);
    glTexCoord2f(tx1,ty2);
    glVertex2s(x,y+h);
    glTexCoord2f(tx2,ty2);
    glVertex2s(x+w,y+h);
    glTexCoord2f(tx2,ty1);
    glVertex2s(x+w,y);
    glTexCoord2f(tx1,ty1);
    glVertex2s(x,y);
    glEnd();
#else
    GLfloat box[] = {x,y + h,  x + w,y + h,  x + w, y,   x,y};
    GLfloat tex[] = {tx1,ty2, tx2,ty2, tx2,ty1, tx1,ty1};
 
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
    glColor3f(redfactor,greenfactor,bluefactor);
    glVertexPointer(2, GL_FLOAT, 0, box);
    glTexCoordPointer(2, GL_FLOAT, 0, tex);
 
    glDrawArrays(GL_QUADS,0,4);
 
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#endif

I know so far glColor3f needs to be change i think the glColorPointer. QUADS doesnt exist so I think i need to break this down into 2 triangels. (this was based on Adventus example, but maybe its gles2 only?)
 
Pickle said:
2 big things ive see so far:

Code:
glDrawBuffer(GL_FRONT);
glDrawBuffer(GL_BACK);

u usually dont need this. for a doublebuffered setup the default drawbuffer is the back buffer. so only if you really want to draw to the front buffer then you need to switch to GL_FRONT. but i cant think of any case where this is needed in normal circumstances.


not sure if these are even needed

Code:
#ifndef OPENGLES    
    glBegin(GL_QUADS);
    glColor3f(redfactor,greenfactor,bluefactor);
    glTexCoord2f(tx1,ty2);
    glVertex2s(x,y+h);
    glTexCoord2f(tx2,ty2);
    glVertex2s(x+w,y+h);
    glTexCoord2f(tx2,ty1);
    glVertex2s(x+w,y);
    glTexCoord2f(tx1,ty1);
    glVertex2s(x,y);
    glEnd();
#else
    GLfloat box[] = {x,y + h,  x + w,y + h,  x + w, y,   x,y};
    GLfloat tex[] = {tx1,ty2, tx2,ty2, tx2,ty1, tx1,ty1};
 
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
    glColor3f(redfactor,greenfactor,bluefactor);
    glVertexPointer(2, GL_FLOAT, 0, box);
    glTexCoordPointer(2, GL_FLOAT, 0, tex);
 
    glDrawArrays(GL_QUADS,0,4);
 
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#endif

I know so far glColor3f needs to be change i think the glColorPointer. QUADS doesnt exist so I think i need to break this down into 2 triangels. (this was based on Adventus example, but maybe its gles2 only?)

you're right about the QUADS, splitting into 2 triangles you need.
if you dont need colorpointers at all and the code only relies on glColor* calls, you can use glColor4f instead with the alpha set to 1.0 (which implicitly is done by glColor3f)

*edit*
with glColor4f you're only able to set the color for the whole mesh you draw. if you need per-vertex colors you need to use glColorPointer stuff.
 
Last edited by a moderator:
Ok for now ive defined out the DrawBuffers

Heres what ive ended up for the QUADS replacement
Code:
    GLfloat tri1[] = {x,y + h,  x + w,y + h,  x + w, y};
    GLfloat tex1[] = {tx1,ty2, tx2,ty2, tx2,ty1};
    
    GLfloat tri2[] = {x,y + h,  x + w, y,   x,y};
    GLfloat tex2[] = {tx1,ty2, tx2,ty1, tx1,ty1};
 
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    
     glColor4f(redfactor,greenfactor,bluefactor,1.0f);
    
    // First Triangle
    glVertexPointer(2, GL_FLOAT, 0, tri1);
    glTexCoordPointer(2, GL_FLOAT, 0, tex1);
 
    glDrawArrays(GL_TRIANGLES,0,3);
    
    // Second Triangle    
    glVertexPointer(2, GL_FLOAT, 0, tri2);
    glTexCoordPointer(2, GL_FLOAT, 0, tex2);
 
    glDrawArrays(GL_TRIANGLES,0,3);
 
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
Pickle said:
Ok for now ive defined out the DrawBuffers

Heres what ive ended up for the QUADS replacement

u dont need to split the triangles into 2 arrays and then call glDrawArrays twice. you're fine using a single array:
Code:
  GLfloat tri1[] = {x,y + h,  x + w,y + h,  x + w, y, x,y + h,  x + w, y,   x,y};
  GLfloat tex1[] = {tx1,ty2, tx2,ty2, tx2,ty1,        tx1,ty2, tx2,ty1, tx1,ty1};
    
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  
  glColor4f(redfactor,greenfactor,bluefactor,1.0f);
  
  glVertexPointer(2, GL_FLOAT, 0, tri1);
  glTexCoordPointer(2, GL_FLOAT, 0, tex1);

  glDrawArrays(GL_TRIANGLES,0,6);
  
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);


there's also a different way that you dont need to send duplicated vertices/texcoords using index arrays.

Code:
    GLfloat vtx[] = {
      x   ,y+h,
      x+w ,y+h,
      x+w ,y  ,
      x   ,y
    };
    
    GLfloat tex[] = {
      tx1,ty2,
      tx2,ty2,
      tx2,ty1,
      tx1,ty1,
    };
    
    GLushort idx[] = {
      0,1,2,
      0,2,3,
    };

  glColor4f(redfactor,greenfactor,bluefactor,1.0f);
    
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FLOAT,0, tex);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT,0, vtx);

    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, idx);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

didnt try the above code, but i think you get it.
 
Last edited by a moderator:
Yep all makes sense ;-)

Code:
    GLfloat vtx[] = {
       0,240,0,
       0,240-yy/90,0,
       360,240-yy/90,0,
       360,240,0
     };
     
     GLushort idx[] = {
       0,1,2,
       0,2,3,
     };
     
     glEnableClientState(GL_VERTEX_ARRAY);
     
     glColor3f(palette[0xe3*3]/64.0*redfactor,
           palette[0xe3*3+1]/64.0*greenfactor,
           palette[0xe3*3+2]/64.0*bluefactor,
           1.0f );
     
     glVertexPointer(3, GL_FLOAT, 0, vtx);
     glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, idx);
 
     glDisableClientState(GL_VERTEX_ARRAY);

what about then the Z coordinate is needed, i just skip those in the id array like so?:
(Iknow in the case above i probally dont need 3 coordinates sense the Z is 0 but there are other cases where its not)

Code:
    GLushort idx[] = {
       0,1,3,
       0,3,4,
     };

Edit: eh, i dont think i need to change it all now that i look at it

Also not sure how to handle:
Code:
 glFrustum(xmin, xmax, ymin, ymax, neardist, 98304.0);

Ive also made these defines, but I will probably need to give the context that they are used in:
Code:
#define GLdouble GLfloat
 #define GL_CLAMP GL_REPEAT
 #define GL_UNPACK_ROW_LENGTH GL_UNPACK_ALIGNMENT
 #define GL_UNPACK_SKIP_PIXELS GL_UNPACK_ALIGNMENT
 #define GL_UNPACK_SKIP_ROWS GL_UNPACK_ALIGNMENT
 #define GL_BGR GL_RGB
 #define GL_RGBA8 GL_RGBA
 #define GL_RGBA4 GL_RGBA
 
hmm, some progress, it sorta runs, lol :rolleyes:
some things are being drawn on screen, look like when i went in game i got the floor and ceiling. I got a bunch of opengl errors printf'ing so at least i have something to track down.

Edit:

Code:
    glBindTexture(GL_TEXTURE_2D,tex);
    checkGLStatus();
    
    glPixelStorei(GL_UNPACK_ROW_LENGTH,screenbufferwidth);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS,x);
    glPixelStorei(GL_UNPACK_SKIP_ROWS,y);
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    checkGLStatus();

Ok i think this is the first bad area, its seems GL_UNPACK_ALIGNMENT is the only option, so i wasnt sure what to do with

GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS
 
PokeParadox said:
You can use GL_TRIANGLE_FAN instead of rendering GL_TRIANGLE twice... I think... I changed my quad drawing to triangle fans and had no issues...

Actually looks like GL_TRIANGLE_STRIP would fit better, but i think the solution crowriot gave should work?

I think the biggest issue is loading the textures correctly.
 
Last edited by a moderator:
Pickle said:
Yep all makes sense ;-)


what about then the Z coordinate is needed, i just skip those in the id array like so?:
(Iknow in the case above i probally dont need 3 coordinates sense the Z is 0 but there are other cases where its not)

Edit: eh, i dont think i need to change it all now that i look at it

when you add a Z coordinate, you dont need to change the index buffer, you only need to change the first glVertexPointer argument from 2 to 3 (i.e. entries used per vertex from the vertex array)


Also not sure how to handle:
Code:
 glFrustum(xmin, xmax, ymin, ymax, neardist, 98304.0);

glFrustum is defined as glFrustumf in opengles (or glFrustumx for fixed point math)

Code:
#define GL_CLAMP GL_REPEAT
GL_CLAMP should be defined, if not try using GL_CLAMP_TO_EDGE. setting it to repeated mode will just look wrong.

Code:
 #define GL_UNPACK_ROW_LENGTH GL_UNPACK_ALIGNMENT
 #define GL_UNPACK_SKIP_PIXELS GL_UNPACK_ALIGNMENT
 #define GL_UNPACK_SKIP_ROWS GL_UNPACK_ALIGNMENT

from what i've read this is used to update sub parts of a texture. i've never used this, and it isnt supported by opengles. so a quick google gave me http://stackoverflow.com/questions/205522/opengl-subtexturing which seems to have a solution for your problem.


Code:
 #define GL_BGR GL_RGB
 #define GL_RGBA8 GL_RGBA
 #define GL_RGBA4 GL_RGBA

i think you should convert all your textures to GL_RGB or GL_RGBA with 8 bit per component before uploading them to the graphics board. this is the easiest way to handle textures.
for sake of memory you could also convert them to 16 bit images. for valid combinations of formats and arguments i suggest to read http://www.khronos.org/opengles/sdk/docs/man/glTexImage2D.xml

You can use GL_TRIANGLE_FAN instead of rendering GL_TRIANGLE twice... I think... I changed my quad drawing to triangle fans and had no issues...

well i havent thought of that solution, but it should work. either GL_TRIANGLE_FAN or GL_TRIANGLE_STRIP, it doesnt matter in this case, it just turns out to be the same.
 
Last edited by a moderator:
crow_riot said:
when you add a Z coordinate, you dont need to change the index buffer, you only need to change the first glVertexPointer argument from 2 to 3 (i.e. entries used per vertex from the vertex array)
Yeah I figured that out after i posted :)

crow_riot said:
glFrustum is defined as glFrustumf in opengles (or glFrustumx for fixed point math)

GL_CLAMP should be defined, if not try using GL_CLAMP_TO_EDGE. setting it to repeated mode will just look wrong.
thanks! level walls are showing up now! the textures are there but diagonal.


crow_riot said:
from what i've read this is used to update sub parts of a texture. i've never used this, and it isnt supported by opengles. so a quick google gave me http://stackoverflow...gl-subtexturing which seems to have a solution for your problem.
ive give this a look over later.

crow_riot said:
i think you should convert all your textures to GL_RGB or GL_RGBA with 8 bit per component before uploading them to the graphics board. this is the easiest way to handle textures.
for sake of memory you could also convert them to 16 bit images. for valid combinations of formats and arguments i suggest to read http://www.khronos.o...lTexImage2D.xml
ill look into doing this

crow_riot said:
well i havent thought of that solution, but it should work. either GL_TRIANGLE_FAN or GL_TRIANGLE_STRIP, it doesnt matter in this case, it just turns out to be the same.

i tried STRIP, but it didnt come out right..so im staying with drawing elements for now
 
Last edited by a moderator:
Pickle, you can use whatever you like to draw a quad, i.e. tri list, tri strip, tri fan, and their indexed forms. just keep in mind the default vertex winding order for visible triangles is CCW. when composing a tristrip, though, you need to start with a CCW tri, then the 2nd one has to be CW, 3rd - CCW again, etc - tris keep alternating their winding in a strip. in case you're wondering how a quad would look as an unindexed strip, here's a recent post from another thread that shows how to define a quad as a tristrip.

btw, what exactly are you trying to achieve with the glPixelStore? what is the layout of the bitmap buffer you try to upload?
 
Last edited by a moderator:
darkblu said:
btw, what exactly are you trying to achieve with the glPixelStore? what is the layout of the bitmap buffer you try to upload?

I think its a tile sheet and parts of the sheet are loaded to the texture.
 
Last edited by a moderator:
Pickle said:
I think its a tile sheet and parts of the sheet are loaded to the texture.
ES' pixelbuffer-describing abilities are not as flexible as desktop GL. why don't you upload the entire tile sheet, and use tex transforms (i.e. glMatrixMode(GL_TEXTURE)) to select individual tiles?
 
Last edited by a moderator:
darkblu said:
Pickle said:
I think its a tile sheet and parts of the sheet are loaded to the texture.
ES' pixelbuffer-describing abilities are not as flexible as desktop GL. why don't you upload the entire tile sheet, and use tex transforms (i.e. glMatrixMode(GL_TEXTURE)) to select individual tiles?

i dont know this engine that well and i not exactly the best at opengles, I need to keep looking. My plan was to replace opengl with as much opengles as i could.
 
Last edited by a moderator:
in that case you might need to extract the needed portion from the sheet into a separate buffer, just for the upload.
 
Ok heres the one place where the sub image to texture is really used, most places glPixelStorei is passed 0 (basically doing nothing)
Ive tried to put the glTexSubImage2D loops in there, but i dont know it that makes sense to, seems like the glTexImage2D should be looped.


Code:
/* Upload rectangular part of overlay from memory to specified texture. */

void UploadPartialOverlayToTexture(int x,int y,int dx,int dy,int w,int h,
                   GLuint tex,int create) {
#ifdef OPENGLES  
    int yy;
#endif    
  
    glBindTexture(GL_TEXTURE_2D,tex);
    checkGLStatus();
    
#ifndef OPENGLES
    glPixelStorei(GL_UNPACK_ROW_LENGTH,screenbufferwidth);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS,x);
    glPixelStorei(GL_UNPACK_SKIP_ROWS,y);
#endif
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    checkGLStatus();

    if (create) {
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,partialfilter);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,partialfilter);
    }

    //glPixelTransferi(GL_MAP_COLOR,GL_TRUE);

    if (debugmode)
    fprintf(stderr,"Partial overlay upload (%d %d %d %d)... ",
        w,h,dx,dy);


    if (create) {
    if (debugmode)
        fprintf(stderr,"(create) ");
    glTexImage2D(GL_TEXTURE_2D,0,colourformat,w,
             h,0,GL_RGBA,
             GL_UNSIGNED_BYTE,
             screenbuffer32);
#ifdef OPENGLES      
    for( yy = 0; yy < h; yy++ )
    {
        char *row = screenbuffer32 + ((yy + y)*screenbufferwidth + x) * 4;
        glTexSubImage2D( GL_TEXTURE_2D, 0, 0, yy, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, row );
    }
#endif
    } else {
    glTexSubImage2D(GL_TEXTURE_2D,0,dx,dy,w,h,
            GL_RGBA,
            GL_UNSIGNED_BYTE,
            screenbuffer32);
#ifdef OPENGLES  
    for( yy = 0; yy < h; yy++ )
    {
        char *row = screenbuffer32 + ((yy + y)*screenbufferwidth + x) * 4;
        glTexSubImage2D( GL_TEXTURE_2D, 0, 0, yy, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, row );
    }
#endif
    }
    checkGLStatus();
    if (debugmode)
    fprintf(stderr,"done.\n");
    //glPixelTransferi(GL_MAP_COLOR,GL_FALSE);
#ifndef OPENGLES    
    glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
    glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
#endif
}
 
duh, totally forgot about glTexSubImage. of course it should help you.

just a remark, though: in the 'create' branch of the control flow, at the glTexImage2D call - if you intention is indeed to just define the texture object, then don't pass valid pointers to data - pass null - it's sufficient for the purpose. also, put the original glTexSubImage call from the 'non-create' branch in an '#ifndef OPENGLES' as you don't want it in the ES case. also in the 'non-create' branch:

Code:
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, yy, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, row );
should read:

Code:
glTexSubImage2D( GL_TEXTURE_2D, 0, dx, dy + yy, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, row );
as that's what the original glTexSubImage does.
 
just fiddled around with your code and the suggestions darkblu made.

i think the following code should make it, in the create case i only pass NULL (to create the texture), and then we'll loop over the screenbuffer and update the subimage. you should check what dx and dy are for the create case, as i assume they are 0.

another thing that comes to my mind - i think in opengl/es the 'colourformat' (internalformat) argument to glTexImage2D must match the externalformat argument (GL_RGBA). so either check what 'colourformat' is or just replace it with GL_RGBA to be safe.


Code:
void UploadPartialOverlayToTexture(int x,int y,int dx,int dy,int w,int h,
                   GLuint tex,int create) {
#ifdef OPENGLES  
    int yy;
#endif    
  
    glBindTexture(GL_TEXTURE_2D,tex);
    checkGLStatus();
    
#ifndef OPENGLES
    glPixelStorei(GL_UNPACK_ROW_LENGTH,screenbufferwidth);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS,x);
    glPixelStorei(GL_UNPACK_SKIP_ROWS,y);
#endif
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    checkGLStatus();

    if (create) {
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,partialfilter);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,partialfilter);
    }

    //glPixelTransferi(GL_MAP_COLOR,GL_TRUE);

    if (debugmode)
    fprintf(stderr,"Partial overlay upload (%d %d %d %d)... ",
        w,h,dx,dy);


    if (create) 
    {
    if (debugmode)
        fprintf(stderr,"(create) ");
#ifdef OPENGLES      
    glTexImage2D(GL_TEXTURE_2D,0,colourformat,w,
             h,0,GL_RGBA,
             GL_UNSIGNED_BYTE,
             NULL);
#else
    glTexImage2D(GL_TEXTURE_2D,0,colourformat,w,
             h,0,GL_RGBA,
             GL_UNSIGNED_BYTE,
             screenbuffer32);
#endif             
    }
    else
    {
#ifndef OPENGLES      
    glTexSubImage2D(GL_TEXTURE_2D,0,dx,dy,w,h,
            GL_RGBA,
            GL_UNSIGNED_BYTE,
            screenbuffer32);
#endif            
    }

#ifdef OPENGLES  
    for( yy = 0; yy < h; yy++ )
    {
        char *row = screenbuffer32 + ((yy + y)*screenbufferwidth + x) * 4;
        glTexSubImage2D( GL_TEXTURE_2D, 0, dx, dy+yy, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, row );
    }
#endif
    
    checkGLStatus();
    if (debugmode)
    fprintf(stderr,"done.\n");
    //glPixelTransferi(GL_MAP_COLOR,GL_FALSE);
#ifndef OPENGLES    
    glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
    glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
#endif
}
 
awesome guys we are one step closer, i see intro screens, text is showing some places.
textures are not square...maybe i messed up the arrays.
the menu shows sometimes, i think maybe this has to do with the DrawBuffers, maybe adding egl buffer swap would work.

I need to look into the parts where i made:
Code:
#define GL_BGR GL_RGB
 #define GL_RGBA8 GL_RGBA
 #define GL_RGBA4 GL_RGBA

Edit:
oh yeah and i made a correction here:
Code:
char *row = (char*)screenbuffer32 + ((yy + y)*screenbufferwidth + x) * 4;

Edit 2:
GL_BGR doesnt matter really, only used in a screenshot mode

and the others are not and issue as long as the right mode is used:
Code:
    switch(texturedepth) {
	case 1:
	    colourformat=GL_RGBA8;
	    break;
	case 2:
	    colourformat=GL_RGBA4;
	    break;
	default:
	    colourformat=GL_RGBA;
    }
 
Pickle said:
Edit 2:
GL_BGR doesnt matter really, only used in a screenshot mode

and the others are not and issue as long as the right mode is used:
Code:
    switch(texturedepth) {
	case 1:
	    colourformat=GL_RGBA8;
	    break;
	case 2:
	    colourformat=GL_RGBA4;
	    break;
	default:
	    colourformat=GL_RGBA;
    }
the above looks a bit iffy. in what cases is texturedepth 1 and 2, respectively - does it have to do anything with the bitdepth of the image buffers? if it has any relation to those, then you may be better off doing something like:

Code:
    GLint colourformat = GL_RGBA;
    GLint datatype = GL_UNSIGNED_BYTE;

    switch(texturedepth) {
	case 1:
	    colourformat= GL_LUMINANCE;
	    break;
	case 2:
            datatype = GL_UNSIGNED_SHORT_4_4_4_4;
	    break;
        // 4-byte case already initialized by default
    }
(where colourformat and datatype above are passed to glTexImage2D as 3rd, 7th (format) and 8th (type) arguments)

and drop the #define's of GL color formats altogether.
 
Last edited by a moderator:
Back
Top