 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
skwi
Joined: 16 May 2006 Posts: 22
|
Posted: Wed Jul 19, 2006 9:18 pm Post subject: how to set my texture ? |
|
|
I want to use textures from a table with the texture, but this don"t work, somes lignes of my texture are skipped
my textures is :
| Code: |
static unsigned char __attribute__((aligned(16))) texture[]={0x00,0x00, 0xFF,0xFF, 0x00,0x00, 0xFF,0xFF,
0xFF,0xFF, 0x00,0x00, 0xFF,0xFF, 0x00,0x00,
0x00,0x00, 0xFF,0xFF, 0x00,0x00, 0xFF,0xFF,
0xFF,0xFF, 0x00,0x00, 0xFF,0xFF, 0x00,0x00,
0x00,0x00, 0xFF,0xFF, 0x00,0x00, 0xFF,0xFF,
0xFF,0xFF, 0x00,0x00, 0xFF,0xFF, 0x00,0x00,
0x00,0x00, 0xFF,0xFF, 0x00,0x00, 0xFF,0xFF,
0xFF,0xFF, 0x00,0x00, 0xFF,0xFF, 0x00,0x00};
|
I use it like this :
| Code: |
sceGuTexMode(GU_PSM_4444,0,0,0);
sceGuTexImage(0,4,4,4,texture);
sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
sceGuTexEnvColor(0xffff00);
//sceGuTexFilter(GU_LINEAR,GU_LINEAR);
sceGuTexScale(1.0f,1.0f);
sceGuTexOffset(0.0f,0.0f);
|
my texture should be :
W B W B
B W B W
W B W B
B W B W
but the half of the lignes are skipped
and this result in :
W B W B
W B W B
W B W B
W B W B
what i'm doing wrong ?
thank you |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Thu Jul 20, 2006 12:36 am Post subject: Re: how to set my texture ? |
|
|
| skipped lines and alike are often a sign that you have your texture size/stride or pixel format set incorrectly to the rasterizer. Since I can't see anything wrong with that though, it must be in the setup of the texture coordinates you provide with your vertices. Probably they get clipped, so only drawing the first line every time, or maybe they are too large (ie, > 2 times the size they should be, thus skipping lines). Have you set texture clipping to clamp? Try to set it to repeat and see what happens. |
|
| Back to top |
|
 |
skwi
Joined: 16 May 2006 Posts: 22
|
Posted: Thu Jul 20, 2006 12:52 am Post subject: |
|
|
thank you for your help but i have resolved my problem using larger textures, with a 8*8 texture everything work fine
seems like the minimum Texture Buffer Width is 8 because in my old texture (i've put in my first message) i have a 4*4 texture buffer and it skip lines acting like if the Texture Buffer Width was 8 |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Thu Jul 20, 2006 1:10 am Post subject: |
|
|
Hehe, now that you say. 4 pixels * 2 bytes = 8 bytes, but textures need to be aligned to 16 bytes, so every second line is not aligned and gets "skipped" :P
If my theory is correct 32bit 4x4 textures should work. |
|
| Back to top |
|
 |
skwi
Joined: 16 May 2006 Posts: 22
|
Posted: Thu Jul 20, 2006 10:56 pm Post subject: |
|
|
maybe but i haven't test 4*4 in 32 bits but i don"t have any 4*4 textures, it was only a test
but now i've got another problem, with lights, i've add lights to my programm and i can't see any light
i've added
sceGuEnable(GU_LIGHTING);
sceGuEnable(GU_LIGHT0);
with the others GU setup
I've add :
ScePspFVector3 pos = { 0, 1, 0 };
sceGuLight(0,GU_POINTLIGHT,GU_DIFFUSE_AND_SPECULAR,&pos);
sceGuLightColor(0,GU_DIFFUSE,0xffff0000);
sceGuLightColor(0,GU_SPECULAR,0xffffffff);
sceGuSpecular(12.0f);
sceGuAmbient(0x00222222);
into my program to setup the light
and then i've add normals :
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,nb_face*3,0,verticestabl);
my verticestabl is now with normals
but my model is not shaded
i've forgot something ?
thank you for the answer |
|
| Back to top |
|
 |
skwi
Joined: 16 May 2006 Posts: 22
|
Posted: Fri Jul 21, 2006 4:24 am Post subject: |
|
|
actually the light problem was in the makefile
my old makefile :
CFLAGS = -G0 -Wall
I've added "-O2" :
CFLAGS = -G0 -Wall -O2
ans now lighting is working |
|
| Back to top |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
|
| Back to top |
|
 |
skwi
Joined: 16 May 2006 Posts: 22
|
Posted: Sat Jul 22, 2006 8:50 am Post subject: |
|
|
i think you"re right but i can"t find where
and now i've got a very strange problem, when I allocate the memory for my texture, it change the z coordinate of the first point of my mesh
i really don"t understand why i've got all theses strange problems
here is the whole code :
| Code: |
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <malloc.h>
#include <pspgu.h>
#include <pspgum.h>
#include <pspctrl.h>
PSP_MODULE_INFO("3D Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
static unsigned int __attribute__((aligned(16))) list[262144];
float valtest;
int exitRequest = 0;
int running()
{
return !exitRequest;
}
int exitCallback(int arg1, int arg2, void *common)
{
exitRequest = 1;
return 0;
}
int callbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exitCallback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int setupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", callbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
struct objet
{
float *vertices;
int nb_face;
char *texture;
int hauteur;//de la texture
int largeur;//de la texture
char nom[16];
int etat;
float x,y,z,xrot,yrot,zrot;
};
int chargeobj(struct objet* objet)
{
int nb_vert=0, nb_texc=0, nb_norm=0;
(*objet).nb_face=0;
FILE * fichier1;
char ligne[256];
char nomobj[16];
char nomtex[16];
sprintf(nomobj,"%s.txt",(*objet).nom);
sprintf(nomtex,"%s.bmp",(*objet).nom);
fichier1 = fopen ( nomobj , "rb" );//essai d'ouvrir le fichier
if (fichier1!=NULL)//si le fichier est ouvert
{
while (fgets( ligne, 256, fichier1 ) != NULL)//on le lit ligne par ligne
{
switch (ligne[0])//on va regarder le premier caractère
{
case 'v'://si c'est un V
if(ligne[1]==' ') //c'est un vertice
nb_vert++;
if(ligne[1]=='t') //c'est un texcoord
nb_texc++;
if(ligne[1]=='n') //c'est une normale
nb_norm++;
break;
case 'f'://si c'est une face
(*objet).nb_face++;
break;
default:
break;
}
}
//on a compté le nombre, now on aloue la memoire qu'il faut
float *vertx = malloc(nb_vert* sizeof(float));
float *verty = malloc(nb_vert * sizeof(float));
float *vertz = malloc(nb_vert * sizeof(float));
float *texcx = malloc(nb_texc * sizeof(float));
float *texcy = malloc(nb_texc * sizeof(float));
float *normx = malloc(nb_norm * sizeof(float));
float *normy = malloc(nb_norm * sizeof(float));
float *normz = malloc(nb_norm * sizeof(float));
int *facevert1 = malloc((*objet).nb_face * sizeof(int));
int *facetexc1 = malloc((*objet).nb_face * sizeof(int));
int *facenorm1 = malloc((*objet).nb_face * sizeof(int));
int *facevert2 = malloc((*objet).nb_face * sizeof(int));
int *facetexc2 = malloc((*objet).nb_face * sizeof(int));
int *facenorm2 = malloc((*objet).nb_face * sizeof(int));
int *facevert3 = malloc((*objet).nb_face * sizeof(int));
int *facetexc3 = malloc((*objet).nb_face * sizeof(int));
int *facenorm3 = malloc((*objet).nb_face * sizeof(int));
rewind(fichier1);//on rembobine le fichier au debut
int v=0,vt=0,vn=0,f=0;
while (fgets( ligne, 256, fichier1 ) != NULL)//on le relit ligne par ligne
{
switch (ligne[0])//on va regarder le premier caractère
{
case 'v'://si c'est un V
if(ligne[1]==' ') //c'est un vertice
{
if( sscanf( ligne + 2, "%f %f %f", vertx + v, verty + v, vertz + v ) == 3 )
{
v+=1;
}
}
if(ligne[1]=='t') //c'est un texcoord
{
if( sscanf( ligne + 2, "%f %f", texcx + vt, texcy + vt ) == 2 )
{
vt+=1;
}
}
if(ligne[1]=='n') //c'est une normale
{
if( sscanf( ligne + 2, "%f %f %f", normx + vn, normy + vn , normz + vn ) == 3 )
{
vn+=1;
}
}
break;
case 'f'://si c'est une face
if( sscanf( ligne + 2, "%d/%d/%d %d/%d/%d %d/%d/%d", facevert1+f, facetexc1+f , facenorm1+f, facevert2+f, facetexc2+f , facenorm2+f, facevert3 + f, facetexc3 + f , facenorm3 + f) == 9 )
{
f+=1;
}
break;
default:
break;
}
}
fclose (fichier1);
(*objet).vertices = memalign(24*(*objet).nb_face*sizeof(float),16);
int i;
for(i=0;i<(*objet).nb_face;i++)
{
int j;
//pour le premier point
j=facetexc1[i]-1;
(*objet).vertices[24*i] = texcx[j];
(*objet).vertices[24*i+1] = texcy[j];
j=facenorm1[i]-1;
(*objet).vertices[24*i+2] = normx[j];
(*objet).vertices[24*i+3] = normy[j];
(*objet).vertices[24*i+4] = normz[j];
j=facevert1[i]-1;
(*objet).vertices[24*i+5] = vertx[j];
(*objet).vertices[24*i+6] = verty[j];
(*objet).vertices[24*i+7] = vertz[j];
//pour le deuxiemme point
j=facetexc2[i]-1;
(*objet).vertices[24*i+8] = texcx[j];
(*objet).vertices[24*i+9] = texcy[j];
j=facenorm2[i]-1;
(*objet).vertices[24*i+10] = normx[j];
(*objet).vertices[24*i+11] = normy[j];
(*objet).vertices[24*i+12] = normz[j];
j=facevert2[i]-1;
(*objet).vertices[24*i+13] = vertx[j];
(*objet).vertices[24*i+14] = verty[j];
(*objet).vertices[24*i+15] = vertz[j];
//pour le troisiemme point
j=facetexc3[i]-1;
(*objet).vertices[24*i+16] = texcx[j];
(*objet).vertices[24*i+17] = texcy[j];
j=facenorm3[i]-1;
(*objet).vertices[24*i+18] = normx[j];
(*objet).vertices[24*i+19] = normy[j];
(*objet).vertices[24*i+20] = normz[j];
j=facevert3[i]-1;
(*objet).vertices[24*i+21] = vertx[j];
(*objet).vertices[24*i+22] = verty[j];
(*objet).vertices[24*i+23] = vertz[j];
}
free(vertx);
free(verty);
free(vertz);
free(texcx);
free(texcy);
free(normx);
free(normy);
free(normz);
free(facevert1);
free(facetexc1);
free(facenorm1);
free(facevert2);
free(facetexc2);
free(facenorm2);
free(facevert3);
free(facetexc3);
free(facenorm3);
}
else//sinon c'est que le fichier n'a pas pu etre ouvert
{
return 0;//pspDebugScreenPrintf("Erreur le fichier n'a pu être ouvert");
}
//fin du loader
valtest=(*objet).vertices[7];
//début du loader de bitmap
FILE * fichier2;
fichier2 = fopen ( nomtex , "rb" );//essai d'ouvrir le fichier
if (fichier2==NULL)//si le fichier n'est ouvert
return 0;
fseek(fichier2, 0x12, SEEK_SET);
fread(&((*objet).largeur),sizeof(int),1,fichier2);//largeur contient maintenant la largeur
fseek(fichier2, 0x16, SEEK_SET);
fread(&((*objet).hauteur),sizeof(int),1,fichier2);//largeur contient maintenant la largeur
(*objet).texture = memalign((*objet).hauteur * (*objet).largeur * 4 * sizeof(float),16);
valtest=(*objet).vertices[7];
fseek(fichier2, 0x36, SEEK_SET);
int i=0;
while(i<(*objet).hauteur*(*objet).largeur*4)
{
fread((*objet).texture+i+2,sizeof(char),1,fichier2);//lit l'information "rouge"
i++;
fread((*objet).texture+i,sizeof(char),1,fichier2);//lit l'information "vert"
i++;
fread((*objet).texture+i-2,sizeof(char),1,fichier2);//lit l'information "bleu"
i++;
(*objet).texture[i]=0xFF;//pour l'alpha on met ça
i++;
}
(*objet).etat=1;
return 1;
}
int dessineobj(struct objet* objet)
{
sceGumLoadIdentity();//locate and rotate
{
ScePspFVector3 pos = { (*objet).x, (*objet).y, (*objet).z };
ScePspFVector3 rot = { (*objet).xrot, (*objet).yrot, (*objet).zrot };
sceGumTranslate(&pos);
sceGumRotateXYZ(&rot);
}
// setup texture
sceGuTexMode(GU_PSM_8888,0,0,0);
sceGuTexImage(0,(*objet).largeur,(*objet).hauteur,(*objet).largeur,(*objet).texture);
sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGB);
sceGuTexEnvColor(0xffff00);
sceGuTexFilter(GU_LINEAR,GU_LINEAR);
sceGuTexScale(1.0f,1.0f);
sceGuTexOffset(0.0f,0.0f);
sceGuAmbientColor(0xffffffff);
sceGuColor(0xffffff);
// dessine le mesh
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,(*objet).nb_face*3,0,(*objet).vertices);
return 1;
}
int dechargeobj(struct objet* objet)
{
free((*objet).vertices);
free((*objet).texture);
return 1;
}
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
int main(int argc, char* argv[])
{
setupCallbacks();
SceCtrlData pad;
pspDebugScreenInit();
struct objet objetest;
objetest.etat=0;
sprintf(objetest.nom,"test");
objetest.x=0;
objetest.y=0;
objetest.z=-2.5;
objetest.xrot=0;
objetest.yrot=0;
objetest.zrot=0;
chargeobj(&objetest);
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)(4*BUF_WIDTH*SCR_HEIGHT),BUF_WIDTH);
sceGuDepthBuffer((void*)(8*BUF_WIDTH*SCR_HEIGHT),BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(65535,0);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuDepthFunc(GU_GEQUAL);
sceGuEnable(GU_DEPTH_TEST);
sceGuFrontFace(GU_CCW);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_CULL_FACE);
sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_CLIP_PLANES);
sceGuEnable(GU_LIGHTING);
sceGuEnable(GU_LIGHT0);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
float x=0,y=0,z=0,xrot=0,yrot=0,zrot=0;
while(running())
{
pspDebugScreenSetXY(0, 1);
pspDebugScreenPrintf("test 3 : commandes");
pspDebugScreenSetXY(0, 2);
int T;
for(T=0;T<8;T++)
{
pspDebugScreenPrintf("%f,",objetest.vertices[T]);
}
pspDebugScreenSetXY(0, 4);
pspDebugScreenPrintf("val :%f",valtest);
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_UP){
x+=-sin(yrot)*.1;
z+=cos(yrot)*.1;
}
if (pad.Buttons & PSP_CTRL_DOWN){
x-=-sin(yrot)*.1;
z-=cos(yrot)*.1;
}
if (pad.Buttons & PSP_CTRL_LEFT){
yrot-=.1;
}
if (pad.Buttons & PSP_CTRL_RIGHT){
yrot+=.1;
}
sceGuStart(GU_DIRECT,list);
sceGuClearColor(0xff554433);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
ScePspFVector3 pos = { 0, 1, 0 };
sceGuLight(0,GU_DIRECTIONAL,GU_DIFFUSE_AND_SPECULAR,&pos);
sceGuLightColor(0,GU_DIFFUSE,0x88888888);
sceGuLightColor(0,GU_SPECULAR,0xffffffff);
sceGuLightAtt(0,0.0f,1.0f,0.0f);
sceGuSpecular(12.0f);
sceGuAmbient(0x00222222);
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
{
ScePspFVector3 pos = { x, y, z };
ScePspFVector3 rot = { xrot, yrot,zrot };
sceGumRotateXYZ(&rot);
sceGumTranslate(&pos);
}
sceGumMatrixMode(GU_MODEL);
dessineobj(&objetest);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
dechargeobj(&objetest);
sceGuTerm();
sceKernelExitGame();
return 0;
}
|
if you can help me
i think I missed something really big but i don"t now what |
|
| Back to top |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
Posted: Sat Jul 22, 2006 7:29 pm Post subject: |
|
|
Hey, you're using memalign backwards! The blockalign parameter (16) should be first.
That should explain most of your problems :)
Of course, there could be more problems, I didn't spend a lot of time reading your code. _________________ http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come. |
|
| Back to top |
|
 |
skwi
Joined: 16 May 2006 Posts: 22
|
Posted: Sat Jul 22, 2006 9:50 pm Post subject: |
|
|
oh thank you, this solve all my problems
now it's working fine (but i think i'll find another problem later)
thank you for your help |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|