Problem with translucent textures
Posted: Thu May 28, 2009 12:24 pm
Hello, I've searched in the forum and found nothing about my current problem : translucent textures.
Well I've some solid polys with no texture, and some others with a translucent (GL_RGB8_A5) texture. But when rendering something appears for a fraction of a second and then nothing is shown at all.
I've reduced my code to as little I could so I can show it here :
Has anyone ever experienced something like my problem ? Or is there a mistake, or something missing in my code ?
I would greatly appreciate any help, thanks a lot.
Well I've some solid polys with no texture, and some others with a translucent (GL_RGB8_A5) texture. But when rendering something appears for a fraction of a second and then nothing is shown at all.
I've reduced my code to as little I could so I can show it here :
Code: Select all
#include <nds.h>
#include <malloc.h>
u8* TranslucentTex;
int TranslucentTexId;
u16 TranslucentTexPal[8];
int TranslucentTexPalAddr;
void CreateTranslucentTexture(void)
{
int x, y;
TranslucentTex = (u8*)malloc(32*32);
for(y=0; y<32; y++) {
for(x=0; x<32; x++) {
TranslucentTex[x + y*32] = ((31-x)<<3) | (x&y);
}
}
for(x=0; x<8; x++) {
TranslucentTexPal[x] = RGB15(x<<2, x<<1, x<<3);
}
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &TranslucentTexId);
glBindTexture(GL_TEXTURE_2D, TranslucentTexId);
glTexImage2D(0, 0, GL_RGB8_A5 , TEXTURE_SIZE_32, TEXTURE_SIZE_32, 0, TEXGEN_TEXCOORD, TranslucentTex);
TranslucentTexPalAddr = gluTexLoadPal(TranslucentTexPal, 8, GL_RGB8_A5);
free(TranslucentTex);
}
void Init3D()
{
videoSetMode(MODE_5_3D);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_TEXTURE_SLOT3);
vramSetBankC(VRAM_C_LCD);
vramSetBankD(VRAM_D_LCD);
vramSetBankE(VRAM_E_TEX_PALETTE);
glInit();
glViewport(0, 0, 255, 191);
glClearColor(0, 0, 0, 0);
glClearDepth(GL_MAX_DEPTH);
glClearPolyID(63);
glEnable(GL_ANTIALIAS);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, 256.0 / 192.0, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
CreateTranslucentTexture();
}
void Draw3D(int theta)
{
glLoadIdentity();
glTranslatef(0, 0, -3);
glRotatef32i(theta, 1<<12, 1<<12, 1<<12);
glEnable(GL_BLEND);
glPolyFmt(POLY_ID(1) | POLY_ALPHA(31) | POLY_CULL_NONE);
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUAD);
glColor(RGB15(31, 31, 31));
glVertex3f(-1, 1, -1);
glVertex3f(-1,-1, -1);
glVertex3f( 1,-1, -1);
glVertex3f( 1, 1, -1);
glEnd();
glPolyFmt(POLY_ID(2) | POLY_ALPHA(31) | POLY_CULL_NONE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, TranslucentTexId);
glColorTable(GL_RGB8_A5, TranslucentTexPalAddr);
glBegin(GL_QUAD);
glTexCoord2t16(0, 0);
glVertex3f(-1, 1, 0);
glTexCoord2t16(0, 0);
glVertex3f(-1,-1, 0);
glTexCoord2t16(1, 0);
glVertex3f( 1,-1, 0);
glTexCoord2t16(1, 0);
glVertex3f( 1, 1, 0);
glEnd();
glFlush(0);
}
int main()
{
int theta = 0;
Init3D();
while(1) {
Draw3D(theta<<4);
theta++;
}
return 0;
}
I would greatly appreciate any help, thanks a lot.