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 > Using more than 1 texture

#42273 - iainprice - Sun May 08, 2005 9:47 pm

If I have 2 texture bin files. How do I set it up so that I draw one 3d object with one texture and then another with another....

[code]
#include "model1_bin.h"
#include "model2_bin.h"
#include "tex1_bin.h"
#include "tex2_bin.h"

int textureID1;
int textureID2;

vramSetBankA(VRAM_A_TEXTURE);
vramSetBankB(VRAM_B_TEXTURE);

glGenTextures(1, &textureID1);
glGenTextures(2, &textureID2);

glBindTexture(0, textureID1);
draw3d(model1_bin);

glBindTexture(0, textureID2);
draw3d(model2_bin);
[/code]

#42277 - bluescrn - Sun May 08, 2005 10:04 pm

you need to use glTexImage2D to get even a single texture to work...

But be aware that iDeaS 1.0.0.4 can't handle more than one texture. It works fine on hardware, though.

#42280 - iainprice - Sun May 08, 2005 10:57 pm

so if I...

[code]
#include "model1_bin.h"
#include "model2_bin.h"
#include "tex1_bin.h"
#include "tex2_bin.h"

int textureID1;
int textureID2;

vramSetBankA(VRAM_A_TEXTURE);
vramSetBankB(VRAM_B_TEXTURE);

glGenTextures(1, &textureID1);
glGenTextures(2, &textureID2);

glBindTexture(0, textureID1);
glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256, TEXTURE_SIZE_256, 0, 0, (u8*)texture1_bin);
draw3d(model1_bin);

glBindTexture(0, textureID2);
glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256, TEXTURE_SIZE_256, 0, 0, (u8*)texture2_bin);
draw3d(model2_bin);
[/code]

it still doesn't want to work, but my texture bins may be wrong.... do I need to bind again or anything if I call the draw commands in a loop or are the textures perminently resident?

#42301 - Ethos - Mon May 09, 2005 4:29 am

iainprice wrote:
glGenTextures(2, &textureID2);


Bad, should be "glGenTextures(1,&textureID2); or even better is make an array called "int textureID [2];" and go "glGenTexture(2,&(textureID[0]));


Your texture's bin file should be of size 256*256*2 = 131072 bytes. Also it is better to bind textures, then load, and then bind later before A redraw.

ie.

glBindTexture(0, textureID1);
glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256, TEXTURE_SIZE_256, 0, 0, (u8*)texture1_bin);
glBindTexture(0, textureID2);
glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256, TEXTURE_SIZE_256, 0, 0, (u8*)texture2_bin);

while (1) {
glBindTexture(0, textureID1);
draw3d(model1_bin);
glBindTexture(0, textureID2);
draw3d(model2_bin);
}
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)

#42413 - floatstarpx - Wed May 11, 2005 1:43 am

on a similar note - how do you switch off texturing once it's you've started?
i've tried lots of ways (glDisable(GL_TEXURE_2D), glResetTextures(), glBindTexture(0, 0), etc..).
any 'proper' way to do it?

#42416 - Ethos - Wed May 11, 2005 2:05 am

floatstarpx wrote:
on a similar note - how do you switch off texturing once it's you've started?
i've tried lots of ways (glDisable(GL_TEXURE_2D), glResetTextures(), glBindTexture(0, 0), etc..).
any 'proper' way to do it?


Huh? Not getting your point....just don't use texture coordinates.
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)

#42436 - floatstarpx - Wed May 11, 2005 1:31 pm

Ethos wrote:
floatstarpx wrote:
on a similar note - how do you switch off texturing once it's you've started?
i've tried lots of ways (glDisable(GL_TEXURE_2D), glResetTextures(), glBindTexture(0, 0), etc..).
any 'proper' way to do it?


Huh? Not getting your point....just don't use texture coordinates.


if you don't use texture coordinates it will use one pixel of the texture for the entire surface (ie all texture coordinates will be 0,0 - or whatever the last ones you entered were). this means all my other textures are tinted the colour of one pixel of the last one! ;)

#42446 - Ethos - Wed May 11, 2005 5:26 pm

Hmmm.... maybe this'll work

Code:
GFX_TEX_FORMAT = 0;

_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)

#42485 - mike260 - Wed May 11, 2005 11:01 pm

floatstarpx wrote:
on a similar note - how do you switch off texturing once it's you've started?
i've tried lots of ways (glDisable(GL_TEXURE_2D), glResetTextures(), glBindTexture(0, 0), etc..).
any 'proper' way to do it?


glDisable(GL_TEXTURE_2D) should do it. Note however that glReset() will reset texturing to being enabled.

#42683 - Ethos - Fri May 13, 2005 11:44 pm

I submitted some code to ndslib to fix the glBindTexture (0,0) problem.

It won't work in any emulators right now anyways.

See demo at dsdev.atspace.com : its the Mixed Cubes demo
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)