#158785 - ragefury32 - Tue Jun 17, 2008 10:37 pm
Hi - newbie here trying to get into NDS programming.
Trying to modify the NeHe OpenGL/DS demos for figuring out the system, and ran into some issues with Demo #8 - I am trying to modify it so it will accept 6 textures instead of 1, hosted in 6 files tat
Anyways, I figure that the first thing that I'll need to do is to do:
int textures[6];
glGenTextures(6, &textures[0]);
glBindTexture(0, texture[0]);
glTexImage2D(0,0, GL)RGBA, TEXTURE_SIZE_128, TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_A_dta);
And so on...
But here is the question:
a) Do I need to do multiple iterations of glBindTexture() for each of the face that I am loading, for example:
glBindTexture(0, texture[0]);
glTexImage2D(0,0, GL)RGBA, TEXTURE_SIZE_128, TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_A_dta);
glBindTexture(0, texture[1]);
glTexImage2D(0,0, GL)RGBA, TEXTURE_SIZE_128, TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_B_dta);
glBindTexture(0, texture[2]);
glTexImage2D(0,0, GL)RGBA, TEXTURE_SIZE_128, TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_C_dta);
And etc...to load all 6 faces?
b) In my DrawGLScene() function, would I need to do a GLBindTexture(GL_Texture_2D, texture[i]) for each faces i, before I call the drawing functions for it, so it'll bind the correct texture map to each face?
Thanks for the quick response...
#158789 - yellowstar - Tue Jun 17, 2008 11:22 pm
Yes, both a & b are correct.
#158790 - silent_code - Tue Jun 17, 2008 11:23 pm
Welcome to the scene! :^)
I don't know what you mean by "faces" (maybe surfaces of a cube?), but yes, you need to generate, bind and fill "texture objects" for all textures you want to use.
Later, when you want to use a certain texture, you just bind the texture (object) and the next geometry that will be rendered, will use the currently bound texture.
That's it. I hope it helped. :^)
PS: There are ")" instead of "_" in some places of your post. ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#158801 - ragefury32 - Wed Jun 18, 2008 7:09 am
Thanks for the quick replies, folks. Yep, just ran the code and it worked...
Do I need to flip the textures vertically prior to using them in the correct orientation? I was looking at the original NeHe demo with the DrunkCoders logo, and there are upside down. Does NDS have a hardware call to flip textures like glPixelZoom(1,-1), or should I do this on the texture prior to import?
Also, are there demo code available somewhere on loading, say, MilkShape/Quake2 MD2 and rendering them in the NDS? I am trying to figure out how to load more complex meshes and doing OpenGL calls on them.
#158806 - silent_code - Wed Jun 18, 2008 11:56 am
Just search the forum and look at the examples provided with libnds and devkitARM.
You could use the texture matrix to flip textures, but you could also flip them manually in your program. Writing a routine to do that isn't hard to do. :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#159153 - ragefury32 - Thu Jun 26, 2008 9:19 am
Okay, stupid question - but one that I searched the forums front to back and can't find an answer for...
How do you mix flat shaded and texture mapped polygons?
Right now I have a texture map on the "floor", and I am inlaying a series of flat shaded polygons on top as a region of interest to be detected using a gluPicker-like function. For some reason I cannot seem to be able to have the flat shaded polygons and the texture mapped polygon on the bottom "play nice" with each other.
Either the flat shaded polygons disappears right after the first rendering pass, (it shows up and then disappears) or it does not display unless I comment the texture mapped polygons out.
Right now the code looks something like this:
glInit();
glEnable(GL_OUTLINE | GL_TEXTURE_2D);
glSetOutlineColor(0,RGB15(31,31,31));
glClearPolyID(0);
glClearDepth(0x7FFF);
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0));
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUAD);
glVertex3f(-1.7f, 0.01f, 0.6f);
glVertex3f(-1.7f, 0.01f, 1.1f);
glVertex3f(-1.0f, 0.01f, 1.1f);
glVertex3f(-1.0f, 0.01f, 0.6f);
glEnd();
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUAD);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.0f, 0.0f, -2.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.0f, 0.0f, 2.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.0f, 0.0f, 2.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.0f, 0.0f, -2.0f);
glEnd();
In iDeaS the code renders fine as a red box sitting on top of a texture mapped polygon. In an actual Nintendo DS it renders as just the texture map, but during the very first time the app is run I was able to see a red box at the very beginning before it was replaced by the texture map.
Any ideas?
#159159 - silent_code - Thu Jun 26, 2008 11:09 am
Any pics? ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#159185 - ragefury32 - Thu Jun 26, 2008 4:52 pm
Oh, I'll go one step better...I'll provide the source AND the screenshots.
Anyways. Here's what I wanted to see:
[Images not permitted - Click here to view it]
As you can see, iDeaS on my machine seems to have drawn the flat shaded polygons and then the texture below.
Here's what is actually shown:
[Images not permitted - Click here to view it]
I posted my entire sourcebase here:
http://aculei.net/~ragefury/Files/Hope-AMD/Leica2DS-B/
I tried every combination of GLEnable to try to see if I can get flatshaded and texture mapped polygons working. Hell, I am even looking at NeHe Lesson 8 again to see if I can mix flat shaded and texture mapped polygons to work. Do I need to assign a vertex color to each vertex in each flat shaded polygon to get this working properly?
(Yes, the idea is to eventually draw the polygons invisible and only render an outline if/when the region is selected - but this is initial debugging)
#159187 - zeruda - Thu Jun 26, 2008 5:08 pm
You need to glBindTexture(GL_TEXTURE_2D, 0); just before you draw your flat shaded polygon.
#159188 - elhobbs - Thu Jun 26, 2008 5:11 pm
Code: |
glBindTexture(0, 0); |
this will disable texturing until glBindTexture is called again with a valid texture id.
#159190 - ragefury32 - Thu Jun 26, 2008 5:39 pm
Hm. Wow, thanks - that was quick and easy...
Just another quick one, guys...
If I want to draw the flat shaded polygons invisible but retain the outline when it was selected, which Polygon Attribute would I set?
#159204 - silent_code - Thu Jun 26, 2008 9:47 pm
I would try to set it to fully transparent with outlining, but I don't know if it works.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#159207 - ragefury32 - Thu Jun 26, 2008 11:48 pm
silent_code wrote: |
I would try to set it to fully transparent with outlining, but I don't know if it works. |
How would I set transparency on a flat shaded polygon?
#159220 - silent_code - Fri Jun 27, 2008 12:55 pm
Do you know how to set transparency in general?
It's in the polygon attribute.
There's only one problem... you can't make it fully transparent (I forgot that) - that would switch to wireframe mode.
Btw: When it comes to polygon attributes, it doesn't matter how many normals you supply for a poly (flat / smooth shaded). All you need to know, that transparency is per primitive, in contrast to per vertex.
Anyways, read it here: http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#159224 - ragefury32 - Fri Jun 27, 2008 2:46 pm
silent_code wrote: |
Do you know how to set transparency in general?
It's in the polygon attribute.
There's only one problem... you can't make it fully transparent (I forgot that) - that would switch to wireframe mode.
Btw: When it comes to polygon attributes, it doesn't matter how many normals you supply for a poly (flat / smooth shaded). All you need to know, that transparency is per primitive, in contrast to per vertex.
Anyways, read it here: http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes |
Thanks...The wireframe mode is actually what I wanted. The idea is really to draw nothing unless a region is picked, and when it is, draw it as a white wireframe polygon. I actually did this:
if(clicked == DESIRED_REGION_A) {
glPolyFmt(POLY_ALPHA(0) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0));
iprintf("\x1b[16;0HCurrently at Region A \n");
...
glEnd();
}
if(clicked == DESIRED_REGION_B) {
glPolyFmt(POLY_ALPHA(0) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0));
iprintf("\x1b[16;0HCurrently at Region A \n");
...
(And etc)
And it worked beautifully.
Thanks for the quick heads-up, guys...
#159226 - silent_code - Fri Jun 27, 2008 4:39 pm
I'm glad to be of any help. :^)
A short sidenote: I suggest using "switch / case" or at least "if" + "else if"s instead of the "if"s. :^)
Or even better (if possible) using an array of premade polyformats that can be indexed with those region ids... there are many possible ways to solve that "problem." :^)
Happy programming!
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.