gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Problem with textures and color of objects

#171889 - magge - Thu Dec 31, 2009 4:19 pm

hello guys,

i'm new to this board and have started developing a starfox like game for the ds.

i create my spaceships with simple glvertex commands with tiangles or quads. like this:
Code:
void ShipOne::drawShip(){
  glColor3f(0.1,0.3,1.0);
   glBegin(GL_TRIANGLES);
   
   //upper Left
   glVertex3f(0.0,0.2,0.0);
   glVertex3f(0.0,0.0,-1.0);
   glVertex3f(-0.5,0.0,0.4);
   
   //upper right
   glVertex3f(0.0,0.2,0.0);
   glVertex3f(0.0,0.0,-1.0);
   glVertex3f(0.5,0.0,0.4);
           
            ...
       glEnd();
}


i have a showroom at the beginning of the game to look at the ships. they have the color that i assigned to them.

now comes the part i can't understand. i created a raw image .bin file with gfx2gba and used the code parts from the example "textured quad" from the devkitpro package. i do this in the main method concerning textures:

Code:

            glEnable(GL_TEXTURE_2D);
   vramSetBankA(VRAM_A_TEXTURE);

   glGenTextures(1, &textureID);
   glBindTexture(0, textureID);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD, (u8*)space_bin);   


to draw the textured quad which should stay still in the background of my scene, i do this:

Code:

  void drawTexturedPlane(){
  glPushMatrix();
  glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK);
  glTranslatef(0.0,0.0,-2.0);
  glScalef(8.0,8.0,8.0);
  glBindTexture(0, textureID);
  glColor3f(1.0,1.0,1.0);
  //draw the obj
   glBegin(GL_QUAD);
      //glNormal(NORMAL_PACK(0,inttov10(-1),0));
         GFX_TEX_COORD = (TEXTURE_PACK(0, inttot16(256)));
         glVertex3v16(floattov16(-0.5),   floattov16(-0.5), 0 );
   
         GFX_TEX_COORD = (TEXTURE_PACK(inttot16(256),inttot16(256)));
         glVertex3v16(floattov16(0.5),   floattov16(-0.5), 0 );
   
         GFX_TEX_COORD = (TEXTURE_PACK(inttot16(256), 0));
         glVertex3v16(floattov16(0.5),   floattov16(0.5), 0 );

         GFX_TEX_COORD = (TEXTURE_PACK(0,0));
         glVertex3v16(floattov16(-0.5),   floattov16(0.5), 0 );
      
      glEnd();
      
      glPopMatrix(1);
}


but whenever i draw this quad (which looks just like it should), i have the problem, that the darker the texture itself (a space texture with a lot of black in my case) leads to the occurance, that all objects rendered into the same scene as the quad change its color to black or close to black. they just seem to lose their color information.

this is my complete display function:
Code:

   glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   gluLookAt(0.0,0.0,3.0,0.0,0.0,0.0,0.0,1.0,0.0);
   
   glPushMatrix();
   glTranslatef(current_ship.getShipX(),current_ship.getShipY(),0.0);
   glRotateX(rotX);
   glRotateZ(rotZ);
   if(current_ship.getShipId()==1){
    ShipOne sh=static_cast<ShipOne>(current_ship);
    sh.drawShip();
   }else if(current_ship.getShipId()==2){
    ShipTwo sh=static_cast<ShipTwo>(current_ship);
    sh.drawShip();
  }
  glPopMatrix(1);
 
  drawTexturedPlane();


would be great if anyone knew what was going on with it. i mean it is strange that the brighter the texture itself, the less color information gets lost from my spaceship. i just don't understand why the texture affects the ship's color at all.
and until i disable GL_TEXTURE_2D, the ships color stays black. when i disable textures, then it gets it's original color black.
i do not use lighting.

i'm thankful for any help.

cya

#171892 - headspin - Thu Dec 31, 2009 6:45 pm

Not sure why this would happen if you have no lights? Do you have POLY_CULL_BACK set?

BTW The Nitro Texture Converter included with NitroEngine can convert graphics to all of the non-compressed texture formats.

http://antoniond.drunkencoders.com/nitroengine.html

mod edit: please link to info pages not directly to archives
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171906 - kusma - Fri Jan 01, 2010 2:21 pm

You're experiencing state leaks. Try to call "glDisable(GL_TEXTURE_2D);" at the start of ShipOne::drawShip() (before glBegin).

edit: oh, and you need to call "glEnable(GL_TEXTURE_2D)" again when drawing the textured plane.

#171919 - headspin - Sat Jan 02, 2010 7:03 am

mod edit: please link to info pages not directly to archives

Is this in the rules WinterMute? I'm guessing it was you as no other mod has ever stated this in the 7 odd years I've been a member here. And what about all the hundreds of other direct links on this forum like the third post in this thread? Seems like you've got your work cut out for you if that's the case!
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171923 - magge - Sat Jan 02, 2010 1:31 pm

hey, thanks for the help so far. but it still doesn't work. it only works when i texture_2d is disabled and not enabled again after drawing simple non textured polygons like my spaceship.
so in my display function i draw the ship and then the plane. therefore the textures are enabled again before glflush is called. if i draw the textured plane first, then textures are disabled when flush is called, so i have no textures at all. but this is weird since opengl is state based.

when i switch back to my showroom where there are no textures so far, i disable texture 2d and everything looks good.

i'm pretty confused here. thanks again.

#171926 - elhobbs - Sat Jan 02, 2010 10:00 pm

there is no need to glDisable/glEnable textures if you use polys with and without textures. glEnable(GL_TEXTURE_2D) once to initialize the hardware then call glBindTexture(0, 0) if you do not want a texture applied.

#171928 - magge - Sat Jan 02, 2010 11:55 pm

elhobbs wrote:
there is no need to glDisable/glEnable textures if you use polys with and without textures. glEnable(GL_TEXTURE_2D) once to initialize the hardware then call glBindTexture(0, 0) if you do not want a texture applied.

THANK YOU, perfect. it works. i did not know that one has to execute that line even though no texture is applied to this object.

thanks for all the help.

#171930 - kusma - Sun Jan 03, 2010 2:51 am

elhobbs wrote:
there is no need to glDisable/glEnable textures if you use polys with and without textures. glEnable(GL_TEXTURE_2D) once to initialize the hardware then call glBindTexture(0, 0) if you do not want a texture applied.

From an OpenGL-perspective (not NiroGL, so this post is only me ranting), this is just so wrong that it hurts.

The enable-flags for each texture target is checked in a specified order, to detect if there's texturing enabled for a texture unit. For NitroGL (or, really... "something a bit more OpenGL-ish on Nintendo DS"), that would only be GL_TEXTURE_2D.

glBindTexture(0, 0) should simply generate an GL_INVALID_ENUM error, as zero is not an accepted texture target.

glBindTexture(GL_TEXTURE_2D, 0) (I'm assuming this is what you meant and/or a bizarre side-effect of NiroGL-enum overlaps) would bind texture-name zero to the GL_TEXTURE_2D target, but this isn't really what we want either. Texture-name zero is the default-texture, and can very much contain texture images, so it is not equal to disabling the texture unit.

#171949 - elhobbs - Mon Jan 04, 2010 3:05 am

gl_texture_2d is only used for compatibility on the ds. Passing 0 to glbindtexture works just as well. I did this intentionally. And relax this is not a full OpenGL implementation it is just there to help people get started with 3d on the ds.

#171961 - kusma - Mon Jan 04, 2010 1:45 pm

elhobbs wrote:
And relax this is not a full OpenGL implementation it is just there to help people get started with 3d on the ds.

I did specify that it was just rant, didn't I? And no, it's not "a full OpenGL implementation", it's not an OpenGL implementation at all. To be allowed to call yourself an OpenGL implementation, you need to join the ARB (or the GLES group at Khronos for OpenGL ES), pay some money, and pass the conformancy tests. NiroGL wouldn't be anywhere near passing.