false colors after using textures [solved]
Posted: Wed Sep 22, 2010 6:49 pm
Hello,
I have a problem with using GL textures. After drawing a textured GL Quad object, I can't select the color of a not textured GL Quad object. It's always black. If I commented out drawing the textured object, the other object is colored with the select color. I guess I have to configure or use palettes, but I'm not sure.
Please help!
Thanks,
DaMicha
I have a problem with using GL textures. After drawing a textured GL Quad object, I can't select the color of a not textured GL Quad object. It's always black. If I commented out drawing the textured object, the other object is colored with the select color. I guess I have to configure or use palettes, but I'm not sure.
Please help!
Thanks,
DaMicha
Code: Select all
#include <nds.h>
#include <stdio.h>
#include <math.h>
#include "buttons_256x256.h"
// define textures
static int textureID;
//------------------------------------------------------------------------------
int main()
//------------------------------------------------------------------------------
{
//==== setup video ====
videoSetMode(MODE_0_3D);
glInit();
//==== setup GL ====
// enable antialiasing
glEnable(GL_ANTIALIAS);
glEnable(GL_BLEND);
// setup the rear plane
glClearColor(0,0,0,31); // BG must be opaque for AA to work
glClearPolyID(63); // BG must have a unique polygon ID for AA to work
glClearDepth(0x7FFF);
// Set our view port to be the same size as the screen
glViewport(0,0,255,191);
// setup texture RAM
vramSetBankA(VRAM_A_TEXTURE);
//enable textures
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &textureID);
/* set buttons map */
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXTURE_SIZE_256, TEXTURE_SIZE_256, 0,
TEXGEN_TEXCOORD, (u8*)buttons_256x256Bitmap);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 256.0 / 192.0, 0.1, 30);
// change cull mode
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
// Set the current matrix to be the model matrix
glMatrixMode(GL_MODELVIEW);
//==== main loop ====
while (true)
{
// wait for the screen to refresh
swiWaitForVBlank();
glLoadIdentity();
gluLookAt(0, 0, 10.0, // camara position
0, 0, 0, // look at
0.0, 1.0, 0.0); // direction of up vector
#if 1
/* ==== draw plane 1 ==== */
// bind texture
glBindTexture(GL_TEXTURE_2D, textureID);
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
{
float x = 0;
float y = 0;
float BG_SIZE = 4;
float BG_Z = 4;
glTexCoord2f(0.0, 0.0); glVertex3f(-BG_SIZE+x, BG_SIZE+y, -BG_Z);
glTexCoord2f(1.0, 0.0); glVertex3f( BG_SIZE+x, BG_SIZE+y, -BG_Z);
glTexCoord2f(1.0, 1.0); glVertex3f( BG_SIZE+x, -BG_SIZE+y, -BG_Z);
glTexCoord2f(0.0, 1.0); glVertex3f(-BG_SIZE+x, -BG_SIZE+y, -BG_Z);
}
glEnd();
#endif
/* ==== draw plane 2 ==== */
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glColor3f(1.0, 0.0, 1.0);
{
float x = 3;
float y = 0;
float BG_SIZE = 2;
float BG_Z = 3;
glVertex3f(-BG_SIZE+x, BG_SIZE+y, -BG_Z);
glVertex3f( BG_SIZE+x, BG_SIZE+y, -BG_Z);
glVertex3f( BG_SIZE+x, -BG_SIZE+y, -BG_Z);
glVertex3f(-BG_SIZE+x, -BG_SIZE+y, -BG_Z);
}
glEnd();
// flush to the screen
glFlush(0);
}
return 0;
}