3d kgl pvr texture format

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

3d kgl pvr texture format

Post by tonma »

Hi, I have just create my first own 3d object with the sample code in nehe directory.
Everything works but I can't change the pvr texture file when I try to convert my png file. The one with sample code works.

I tried with texconv whitout succes. I whish to tried texturepacker but need pro version to convert to PVR format

"/home/saturn/dc/texconv-master/texconv.exe -i image/banane.jpg -o image/banane.pvr -f RGB565 -t -p image/preview.png -v"

Which tool can I use for converting to pvr ?
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: 3d kgl pvr texture format

Post by lerabot »

I've also had a lot of trouble with .pvr files. I've been working with .png and .dtex lately.
I'd be interesting in seeing how other are converting files to .pvr.

Tonma, this is how I've been laoding texture in my engine -> http://dcemulation.org/?title=Loading_P ... L_textures
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: 3d kgl pvr texture format

Post by BlueCrab »

As lerabot says, you're probably much better off not using .pvr files. There's almost no reason to use them, over other options that are much easier to handle (.png, .kmg, etc).
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

Thanks,
I have tried your tutorial and made test with VQ format too.

My first 3d textured object on Dreamcast 8-) it's awesome

I have a problem with the transparency of the texture. I have the same problem with the png texture and the VQ texutre. As you can see on the picture I have white color isntead of transparency. Maybe that's come from the emulator Demul.

For the VQ texture, i've used vqenc with -a (ARGB444) or -b format (ARGB1555) and in my code :
$(KOS_BASE)/utils/vqenc/vqenc.exe -t -v -a fruit.png
GL_UNSIGNED_SHORT_5_6_5_VQ_TWID //normal
GL_UNSIGNED_SHORT_1_5_5_5_VQ_TWID //transparency 1-bit (on/off)
GL_UNSIGNED_SHORT_4_4_4_4_VQ_TWID //transparency alpha

Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: 3d kgl pvr texture format

Post by BlueCrab »

Did you set up the proper texture parameters for the alpha to work and did you enable GL_BLEND? Look at the examples/dreamcast/kgl/basic/gl example for how to set that up if you aren't sure how (that seems to be the smallest example that does it, anyway)...
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

Thanks, that's works well.

I added :

glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); //rgbA
glDisable(GL_CULL_FACE);

But also need :
// Set Blend Mode //
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Image
Image
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

Test with animation

Image

Youtube link for the video
https://youtu.be/oGrqbivddEA
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

lerabot wrote: Sun Apr 08, 2018 11:25 am I've also had a lot of trouble with .pvr files. I've been working with .png and .dtex lately.
I'd be interesting in seeing how other are converting files to .pvr.

Tonma, this is how I've been laoding texture in my engine -> http://dcemulation.org/?title=Loading_P ... L_textures
I've tried your script for blender to export an 3d object whitout success. (https://sites.google.com/site/vmusquad/home/blender2dc)
I have blender 2.78c, add your script but nothing in File -> external data
Sorry bad files.
Last edited by tonma on Thu Apr 12, 2018 2:52 am, edited 1 time in total.
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: 3d kgl pvr texture format

Post by lerabot »

I'll give you a proper answer tonight. I might have messed something in the exporter, I've never really tested it at the time ;)

Good to know you got your texture working!
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

Sorry, it's my fault, I didn't use the good file.
Your script works when you make no mistake like me. :oops:

I tried with a plane :

Code: Select all

const float Plane_vertices[4][3] = { 
  { -1.000000f, -1.000000f, 0.000000f }, 
  { 1.000000f, -1.000000f, 0.000000f }, 
  { -1.000000f, 1.000000f, 0.000000f }, 
  { 1.000000f, 1.000000f, 0.000000f }, 
Thanks for this code.
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

I've made more complex test and I have a problem.

I don't think that comes from the python script because I have the same probleme with obj export.
It seems it's only export mesh without contact as you can see on the picture. Maybe beacause I use quad and not triangle.

I have 24 vertices, 22 faces and 44 triangle. Blender export only vertices but no Cube_triangle. (const int Cube_triangles[22][3] = {
};)
Spoiler!
/* Object: Cube */
const int Cube_num_vertices = 24;
const float Cube_vertices[24][3] = {
glVertex3f(1.000000f, 1.000000f, -1.000000f);
glVertex3f(1.000000f, -1.000000f, -1.000000f);
glVertex3f(-1.000000f, -1.000000f, -1.000000f);
glVertex3f(-1.000000f, 1.000000f, -1.000000f);
glVertex3f(0.710271f, 0.710271f, 0.251867f);
glVertex3f(0.710271f, -0.710272f, 0.251867f);
glVertex3f(-0.710271f, -0.710271f, 0.251867f);
glVertex3f(-0.710271f, 0.710271f, 0.251867f);
glVertex3f(1.000000f, 1.000000f, -1.816277f);
glVertex3f(1.000000f, -1.000000f, -1.816277f);
glVertex3f(-1.000000f, -1.000000f, -1.816277f);
glVertex3f(-1.000000f, 1.000000f, -1.816277f);
glVertex3f(-1.852484f, -0.724554f, -1.112420f);
glVertex3f(-1.852484f, 0.724555f, -1.112420f);
glVertex3f(-1.852484f, -0.724554f, -1.703857f);
glVertex3f(-1.852484f, 0.724555f, -1.703857f);
glVertex3f(3.188546f, 0.481773f, -1.018881f);
glVertex3f(3.188546f, -0.481773f, -1.018881f);
glVertex3f(3.188546f, 0.481773f, -1.612773f);
glVertex3f(3.188546f, -0.481773f, -1.612773f);
glVertex3f(3.800824f, 0.176627f, -0.816358f);
glVertex3f(3.800824f, -0.176627f, -0.816358f);
glVertex3f(3.800824f, 0.176627f, -1.147329f);
glVertex3f(3.800824f, -0.176627f, -1.147329f);
};
const int Cube_num_triangles = 22;
const int Cube_triangles[22][3] = {
};
Image

I've modify a little the python raw export script to add the string : glVertex3f(x,y,z); and it's working :
Image
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: 3d kgl pvr texture format

Post by lerabot »

Wow, I'm glad your testing this! Nice updates.
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

I had strange UV mapping errors.
So I have rewrite the python script and now I can export blender to DC with UV mapping for quad polygons. But I need to do some tests before public release with more complex objects and change the text output (i'll create a temporary array to place value).
Now I have :
Spoiler!
loop index 2 Vertex: glVertex3f(1.000000f, 0.999999f, 1.000000f);
loop index 5 Vertex: glVertex3f(-1.000000f, 1.000000f, 1.000000f);
loop index 4 Vertex: glVertex3f(-1.000000f, -1.000000f, 1.000000f);
loop index 3 Vertex: glVertex3f(0.999999f, -1.000001f, 1.000000f);
loop index 0 Vertex: glVertex3f(1.000000f, 1.000000f, -1.000000f);
loop index 2 Vertex: glVertex3f(1.000000f, 0.999999f, 1.000000f);
loop index 3 Vertex: glVertex3f(0.999999f, -1.000001f, 1.000000f);
loop index 1 Vertex: glVertex3f(1.000000f, -1.000000f, -1.000000f);
Loop index 0 (Vertex 2) - UV glTexCoord2f(0.125000f, 1.000000f);
Loop index 1 (Vertex 5) - UV glTexCoord2f(0.000000f, 1.000000f);
Loop index 2 (Vertex 4) - UV glTexCoord2f(0.000000f, 0.875000f);
Loop index 3 (Vertex 3) - UV glTexCoord2f(0.125000f, 0.875000f);
Loop index 4 (Vertex 0) - UV glTexCoord2f(0.250000f, 0.875000f);
Loop index 5 (Vertex 2) - UV glTexCoord2f(0.250000f, 1.000000f);
Loop index 6 (Vertex 3) - UV glTexCoord2f(0.125000f, 1.000000f);
Loop index 7 (Vertex 1) - UV glTexCoord2f(0.125000f, 0.875000f);

And I need something like :
glTexCoord2f(0.125000f, 1.000000f); glVertex3f(1.000000f, 0.999999f, 1.000000f);
The blender viewport blur because I use small texture (64*64)
Image
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: 3d kgl pvr texture format

Post by lerabot »

I feel like working on this sooo much. But I have so much thing to do for work! Shoot me a github link at some point. I'd love to make this compatible with the current openGL implementations.
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

Working version of my modified python script for blender to export quad polygon. :grin:

Code: Select all

glTexCoord2f(0.125000f, 1.000000f); glVertex3f(1.000000f, 0.999999f, 1.000000f);
...
glTexCoord2f(0.000000f, 0.875000f); glVertex3f(-1.000000f, -1.000000f, 1.000000f);
Image
Attachments
blender2dc.zip
(81.27 KiB) Downloaded 56 times
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

The blender export also works for triangulate model : 2310 tri
Image

Need to add light for better effect. But I think I need to add Normal to my export
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

Now with normals for the light. Always 2310 tri.
I need to modify a little the python script when export with triangle or quad for the normals.

Image
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: 3d kgl pvr texture format

Post by lerabot »

You should make a tutorial! Like what's your workflow from the blender model to drawing the mush in game. + lights :D
I'd love to have this!

Look good man!
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

lerabot wrote: Sun Apr 15, 2018 8:24 pm You should make a tutorial! Like what's your workflow from the blender model to drawing the mush in game. + lights :D
I'd love to have this!

Look good man!
Why not, but first need to learn OpenGL ;-)
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: 3d kgl pvr texture format

Post by tonma »

I have made some test and the framerate fall down to 30 fps.
[update ]
I can draw nearly 3000 triangles at 60fps. With/without texture. Not so bad, but I think we can draw more than that.

I used pvr_stats_t for showing the fps :

Code: Select all

sprintf(tmp, "frame rate: %f fps last_time: %f\n",
                   (double)stats.frame_rate, (double)stats.frame_last_time);			   
    bfont_draw_str(vram_s + 10 * 640 + 180, 640, 0, tmp);
I have read somewhere than we must load data of the 3d object in gpu ram to gain speed and not loading all data every frame.

I have tested two way with nearly the same speed, so I certainly not doing the right things :

Code: Select all

glBegin(GL_QUADS);
		glNormal3f(0.00f, -1.00f, 0.00f); 	glTexCoord2f(0.0f, 0.0f);	    glVertex3f(-100.0f, -10.0f, 100.0f);
		glNormal3f(0.00f, 1.00f, 0.00f);		glTexCoord2f(1.0f, 0.0f);	    glVertex3f(100.0f, -10.0f, 1000.0f);
		glNormal3f(0.00f, 1.00f, 0.00f);		glTexCoord2f(1.0f, 1.0f);	    glVertex3f(100.0f, -10.0f, -100.0f);
		glNormal3f(0.00f, 1.00f, 0.00f);		glTexCoord2f(0.0f, 1.0f);	    glVertex3f(-100.0f, -10.0f, -100.0f);
    glEnd();

Code: Select all

GLfloat VERTEX_ARRAY[4 * 3 * 1] = { -100.0f, -10.0f, 100.0f,
                                    100.0f, -10.0f, 100.0f,
                                    100.0f, -10.0f, -100.0f,
                                    -100.0f, -10.0f, -100.0f
                                  };

GLfloat TEXCOORD_ARRAY[4 * 2 * 1] = { 0, 0,
                                      1, 0,
                                      1, 1,
                                      0, 1
                                    };

GLfloat NORMAL_ARRAY[4 * 3 * 1] = { 0, -1, 0,
                                    0, 1, 0,
                                    0, 1, 0,
                                    0, 1, 0
                                  };

GLubyte INDEX_ARRAY[4 * 1] = { 0, 1, 2, 3 };

  // Bind Array Data //
    glNormalPointer(GL_FLOAT, 0, NORMAL_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, 0, TEXCOORD_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, VERTEX_ARRAY);

    // Render the Submitted Vertex Data //
    glDrawElements(GL_QUADS, 4 * 1, GL_UNSIGNED_BYTE, INDEX_ARRAY);
And all the code

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

/* Load a PVR texture - located in pvr-texture.c */
extern GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char glMipMap);

GLfloat VERTEX_ARRAY[4 * 3 * 1] = { -100.0f, -10.0f, 100.0f,
                                    100.0f, -10.0f, 100.0f,
                                    100.0f, -10.0f, -100.0f,
                                    -100.0f, -10.0f, -100.0f
                                  };

GLfloat TEXCOORD_ARRAY[4 * 2 * 1] = { 0, 0,
                                      1, 0,
                                      1, 1,
                                      0, 1
                                    };

GLfloat NORMAL_ARRAY[4 * 3 * 1] = { 0, -1, 0,
                                    0, 1, 0,
                                    0, 1, 0,
                                    0, 1, 0
                                  };

GLubyte INDEX_ARRAY[4 * 1] = { 0, 1, 2, 3 };

static float rx = 1.0f;
void RenderCallback(GLuint texID) {

	glRotatef(rx++, 0, 1, 0);

    // Bind Array Data //
    glNormalPointer(GL_FLOAT, 0, NORMAL_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, 0, TEXCOORD_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, VERTEX_ARRAY);

    // Render the Submitted Vertex Data //
    glDrawElements(GL_QUADS, 4 * 1, GL_UNSIGNED_BYTE, INDEX_ARRAY);
	
}

extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);

int main(int argc, char **argv) {

	int i;
	glKosInit();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, vid_mode->width / vid_mode->height, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    /* Load a PVR texture to OpenGL */
    GLuint texID = glTextureLoadPVR("/rd/wp001vq.pvr", 0, 0);	
	
    // Enable KOS Near Z Vertex Clipping //
    glEnable(GL_KOS_NEARZ_CLIPPING);

    // Set up Light1 - color it red //
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    float lp[4] = { 0.0, 200.0, 0.0, 0.0 };
    float lc[3] = { 1.0f, 0.0f, 0.0f };
    glLightfv(GL_LIGHT0, GL_POSITION, lp);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lc);

	 // Enable 2D Texturing and bind the Texture //
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texID);
	
    while(1) {
	
	
	    // Load Identity and rotate it a bit //
	    glLoadIdentity();
  	
        /* Draw the "scene" */
		for (i=0; i<900; i++){
			RenderCallback(texID);
		}

        /* Finish the frame - Notice there is no glKosBegin/FinshFrame */
        glutSwapBuffers();
		
		
    }

    return 0;
}

Post Reply