(libnds) - glTexImage2D

Post Reply
Discostew
Posts: 103
Joined: Sun Mar 08, 2009 7:24 pm

(libnds) - glTexImage2D

Post by Discostew » Sun Mar 21, 2010 7:42 pm

When working on my "contribution" to libnds, I found a bug in glTexImage2D when loading a texture of type GL_RGB. What it actually does is copies twice the amount because of the variable 'size' is doubled, but information not being written as u8, but as u16 (2 bytes), and size being decremented by 1 each time. If you tried to load this type of texture to a space that wasn't the last one (since original implementations loaded textures linearly), the texture(s) following it would be corrupted.

A simple fix would be to cut the 'size' variable in half if the type is GL_RGB, and the 'texture' parameter isn't NULL.

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: (libnds) - glTexImage2D

Post by dheart88 » Wed Apr 14, 2010 4:36 pm

I found a bug on my DS screen too... the screen is covered by unknown lines... here's part of my coding...

Code: Select all

....
//road
		glGenTextures(1, &texture0);
		glBindTexture(0, texture0);
		glPushMatrix();
			glTexImage2D(0, 0, GL_RGB16, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, map1road_bin);
			glColorTable(GL_RGB16, pal_addr0);			
			glTranslatef(0.00,0.000f,-0.77f);
			glCallList((u32*)map1road3D_bin);
		glPopMatrix(1);
		
		
		//stadium
		glGenTextures(1, &texture1);
		glBindTexture(0, texture1);
		glPushMatrix();				
			glTexImage2D(0, 0, GL_RGB16, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, map1stadium_bin);
			glColorTable(GL_RGB16, pal_addr1);
			glTranslatef(0.00,0.000f,-0.77f);
			glCallList((u32*)map1stadium3D_bin);
		glPopMatrix(1);
....

I'll only give the full source code to the library developer, if you promise me not to publish it.. It's for my final project...

Discostew
Posts: 103
Joined: Sun Mar 08, 2009 7:24 pm

Re: (libnds) - glTexImage2D

Post by Discostew » Wed Apr 14, 2010 6:08 pm

A few questions dheart88,

Are you using gluTexLoadPal to load the palette first, and storing it's returned value into your pal_addr0, pal_addr1 variables (for which you use them as you currently do with glColorTable)? If you aren't, then that would probably be the problem.

Also, is this code used just for initializing, or is this part of the game loop and being executed over and over? I'm not sure because you are loading the textures right before displaying the models.

Perhaps a screen shot of what is happening might help clue us in as to what your problem may be.

EDIT:

I forgot to mention this, but please be advised that unless you can prove that something is buggy within the libraries or toolkits being used, and is not a mistake in your own code, you should be posting in the relevant platform forums such as the libnds forum, as this forum is for bugs found within the toolkits and libraries that are made by the individuals of devkitPro.

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: (libnds) - glTexImage2D

Post by dheart88 » Thu Apr 15, 2010 4:47 am

it works.. yippee... hank you very much.. btw, how can I be helpful to Devkitpro? I want to develop something like window class , etc...

Discostew
Posts: 103
Joined: Sun Mar 08, 2009 7:24 pm

Re: (libnds) - glTexImage2D

Post by Discostew » Thu Apr 15, 2010 4:54 am

Is that code in your first post being ran every frame? If so, then that is your problem. What that is doing is loading the texture graphics into VRAM every frame, when it should only be loaded once at the beginning, and then binded each time you are drawing the models.

Every time you use glTexImage2D to load a texture, it locks all the main VRAM banks into LCDC mode so data can be copied over. If the texture is being loaded during the time the 3D is being rendered, the VRAM is locked up, and you will get unpredictable results. The geometry will be fine, but the texture mapping won't.

EDIT:

Guess you got it fixed. :)

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: (libnds) - glTexImage2D

Post by dheart88 » Thu Apr 15, 2010 4:58 am

Is that code in your first post being ran every frame? yes... that's my fatal mistake :oops:

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests