false colors after using textures [solved]

Post Reply
damicha
Posts: 2
Joined: Wed Sep 22, 2010 6:32 pm

false colors after using textures [solved]

Post by damicha » 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

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;
}
Last edited by damicha on Thu Sep 23, 2010 3:30 pm, edited 1 time in total.

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: false colors after using textures

Post by zeromus » Thu Sep 23, 2010 12:49 am

when did you tell it to quit using the texture? if you didnt tell it to quit using it, then its still using it.

damicha
Posts: 2
Joined: Wed Sep 22, 2010 6:32 pm

Re: false colors after using textures

Post by damicha » Thu Sep 23, 2010 5:48 am

Hello,

that was easy. I added glBindTexture(GL_TEXTURE_2D, 0); to my code before drawing objects without textures and the right colors are drawn. I never did this before and I never had any problems but since I used another texture my colored objects are always black.

Thanks,
DaMicha.

RyouArashi
Posts: 29
Joined: Sun Mar 29, 2009 9:23 pm

Re: false colors after using textures

Post by RyouArashi » Thu Sep 23, 2010 8:31 am

Use

Code: Select all

glBindTexture(GL_TEXTURE_2D, 0);
for untextured polygons.

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: false colors after using textures

Post by zeromus » Thu Sep 23, 2010 8:56 am

I was going to leave it as an educational riddle but i guess that works too

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests