FORUM, Forum Discussion, Forum Gratuit, Nom de domaine, Nom de domaine gratuit, Redirection gratuite,

Forum DCreload  : Tout (ou presque:) sur la seconde vie de la dreamcast Administrateurs :oggy, Cédric
Forum DCreload : Tout (ou presque:) sur la seconde vie de la dreamcast
Non connecté | Se connecter
en ligne : 4 inconnus visitent le forum
Inscription Inscription | Profil Profil | Messages Privés Messages Privés | Recherche Recherche | Online Online | Aide Aide | Créer un blog gratuit

forum Index du forum forumLa programmation forumImage qui bave !!!

Auteur : Sujet: Image qui bave !!!  Bas
 olivier
 Messages postés : 63
 saucisses
 olivier
  Posté le 09/01/2010 18:48:57
Send a private message to olivier
Bonjour tous et bonne année,
Voilà je viens d'écrire un pong. Mais j'ai un problème. Mes images bavent (balle en mouvement) du moins je ne trouve pas l'animation vraiment fluide.
Je n'ai pas pu testé sur Dreamcast car j'utilise lxdream sur linux.
Dois-je utiliser un timer ?

Merci

WHEN DISASTERS STRIKE !!!
 olivier
 Messages postés : 63
 saucisses
 olivier
  Posté le 09/01/2010 18:50:44
Send a private message to olivier
#include <stdio.h>
#include <stdlib.h>
#include <kos.h>
#include <math.h>
#include <png/png.h>
#include "frog.h"

#define delta_t 10
#define width 640
#define fps 30
#define height 480

int tempsavant=0, tempsap = 0;
int frame=0;
   int continuer = 1;
   int mouvement_balle = 0;
int up1=0,up2=0,down1=0,down2=0;

struct Joueur{

int x;
int y;

};
struct Balle{

int x;
int y;
int accx;
int accy;

};

typedef struct Joueur Joueur;
typedef struct Balle Balle;

pvr_ptr_t joueur_1;
pvr_ptr_t joueur_2;
pvr_ptr_t balle;

Balle balle_st;
Joueur joueur1;
Joueur joueur2;
void SDL_Balle() ;
void SDL_Joueur();



typedef struct{
     int x, y;
     int w, h;
} Rect;
 
Rect position;  

//SDL_Rect position;
//SDL_Event event;
//SDL_Surface *score1;
//SDL_Surface *score2;
//SDL_Surface *frame_aff;
//TTF_Font *police;

int score_1 = 0;
int score_2 = 0;
char buf[255];

//SDL_Color blanc = {255,255,255};
//int SDL_Jeu(SDL_Surface* ecran);
//void pause(SDL_Surface* ecran);
//void  gestion_clavier_appuie(SDL_Event *event);
//void gestion_clavier_up(SDL_Event *event);

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


//Initialisation de la SDL
FG_InitPvr();
uint8 c;
cont_cond_t cond;
c=FG_InitPad();

//TTF_Init();
joueur_1 = pvr_mem_malloc(16*64*2);
png_to_texture("/rd/barre.png", joueur_1, PNG_FULL_ALPHA);
//joueur_1 = SDL_LoadBMP("barre.bmp");
joueur_2 = pvr_mem_malloc(16*64*2);
png_to_texture("/rd/barre_b.png", joueur_2, PNG_FULL_ALPHA);
////joueur_2 = SDL_LoadBMP("barre_b.bmp");
balle = pvr_mem_malloc(16*16*2);
png_to_texture("/rd/balle.png", balle, PNG_FULL_ALPHA);
//balle = SDL_LoadBMP("balle.bmp");
//Répétition des touches

//SDL_EnableKeyRepeat(10, 10);

//On initialise les psition des joueurs et la balle
joueur1.x = 10;
joueur1.y = 200;
joueur2.x = 620;
joueur2.y = 200;

balle_st.x = 320;
balle_st.y = 240;
//on initialise l'accélération de la balle
balle_st.accx = 8;
balle_st.accy = -8;


while (1)
{if (cont_get_cond(c, &cond) < 0) {
break;
}
if (!(cond.buttons & CONT_START))
break;
if (!(cond.buttons & CONT_DPAD_UP))
{
joueur1.y -= 16;
if (joueur1.y < 0) joueur1.y = 0;
}
     
    if (!(cond.buttons & CONT_DPAD_DOWN))
{
joueur1.y += 16;
if (joueur1.y > 480-64) joueur1.y = 480-64;

};

if (!(cond.buttons & CONT_Y))
{
joueur2.y -= 16;
if (joueur2.y < 0) joueur2.y = 0;
}

if (!(cond.buttons & CONT_A))
{
joueur2.y += 16;
if (joueur2.y > 480-64) joueur2.y = 480-64;
}

if(!(cond.buttons & CONT_B))
{

//InitBackground();
/*InitLeftBat();
InitRightBat();
InitBall(); */

};

SDL_Balle();
BeginScene();
//SDL_Joueur();
SDL_Jeu();
EndScene();


};

//boucle de jeu
//pause(ecran);

//SDL_FreeSurface(joueur_1);
//SDL_FreeSurface(joueur_2);
//SDL_FreeSurface(balle);



//SDL_FreeSurface(ecran);
//TTF_Quit();
//SDL_Quit();

}

void SDL_Joueur(){

if(up1 & !down1 & joueur1.y >= 2) joueur1.y-=20;
if(!up1 & down1 & joueur1.y <= 420) joueur1.y+=20;
if(up2 & !down2  & joueur2.y >= 2) joueur2.y-=20;
if(!up2 & down2 & joueur2.y <= 420) joueur2.y+=20;
}

/*void pause(SDL_Surface *ecran)
{



   while (continuer)
   
   {
    //gestion du temps
    //tempsap = SDL_GetTicks();
    if(tempsap - tempsavant >fps){
    frame = 1000/(tempsap -tempsavant);
    SDL_Joueur();
    SDL_Balle();    
    //SDL_Jeu();    
tempsavant = tempsap;
} else {

//SDL_Delay(fps - (tempsap - tempsavant));

}
   
       while()){
       switch()
       {
           case SDL_QUIT:
               continuer = 0;break;
           case SDL_KEYDOWN: gestion_clavier_appuie(&event);break;
           case SDL_KEYUP: gestion_clavier_up(&event);break;
           default:break;  
       }
   }
}
}
*/
int SDL_Jeu(){

  //on affichhe pas toutes les images


//On remet à zéero le nombre de  fps
   

//on affiche les scores


//On positionne le fps
position.x = 250;
position.y = 20;
//SDL_BlitSurface(frame_aff,NULL,ecran,&position);

//On positionne le joueur1 suivnat les coordonnées
position.x = joueur1.x;
position.y = joueur1.y;
FG_DrawImg(16,64,joueur1.x,joueur1.y,1, joueur_1);


//On ajoute le joueur2 suivnat les coordonnées
position.x = joueur2.x;
position.y = joueur2.y;
FG_DrawImg(16,64,joueur2.x, joueur2.y ,1, joueur_2);

//on pose la ballle
position.x = balle_st.x;
position.y = balle_st.y;
FG_DrawImg(16,16,balle_st.x,balle_st.y ,1, balle);

//On ajoute les scores
position.x = 100;
position.y = 20;
//SDL_BlitSurface(score1,NULL, ecran,&position);
position.x =470;
//SDL_BlitSurface(score2,NULL, ecran,&position);
//mise à jour de l'écran
//on  met à jour la valeur dui nombre d'image par seconde


//SDL_Flip(ecran);

return 0;
}



void SDL_Balle() {
//on bouge les joueurs

if (mouvement_balle == 0) {

//on rélise les teste sur la balle
//en bas et en haut
if(balle_st.y > height - 10 | balle_st.y< 5)
{

balle_st.accy = -balle_st.accy;


}
//on teste si près du joueur 1
if ( abs(balle_st.y - joueur1.y) < 50 & balle_st.x < 20) {

balle_st.accx = -balle_st.accx;
}
if ( abs(balle_st.y - joueur2.y) < 50 & balle_st.x > (width-30)) {

balle_st.accx = -balle_st.accx;
}

//On teste si le joueuer de gauche a perdu
if (balle_st.x < 0) {

mouvement_balle = 0;
score_2++;
balle_st.x = 320;
balle_st.y = 240;
}

if (balle_st.x > width) {

mouvement_balle = 0;
score_1++;
balle_st.x = 320;
balle_st.y = 240;
}

//on bouge la balle

balle_st.y+=balle_st.accy;
balle_st.x+=balle_st.accx;
//SDL_Delay(1);


}






}

WHEN DISASTERS STRIKE !!!
 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 09/01/2010 19:54:42
Send a private message to Bouz
Personnellement, vu que je ne bosse que sur la DC, je ne me pose même pas la question:
Je me cale sur le balayage de l'écran et chaque itération me prend donc 1/50 ou 1/60 secondes (et c'est constant pendant la partie). Du coup, les animations sont fluides.
Dans ton cas, je vois que tu utilises les fonctions suivantes:
BeginScene();
EndScene();
Avant de faire un BeginScene, SDL n'attend pas le VBL? (dans quel cas tu serais effectivement calé sur le balayage)

 olivier
 Messages postés : 63
 saucisses
 olivier
  Posté le 09/01/2010 23:37:39
Send a private message to olivier
En fait je n'utilises pas la sdl.
J'utilise ma propre lib. Faut que je mette le prog au propre.

Voici le code mis au propre.

#include <stdio.h>
#include <stdlib.h>
#include <kos.h>
#include <math.h>
#include <png/png.h>
#include "frog.h"

#define width 640
#define height 480


   int continuer = 1;
   int mouvement_balle = 0;
int up1=0,up2=0,down1=0,down2=0;

struct Joueur{

int x;
int y;

};
struct Balle{

int x;
int y;
int accx;
int accy;

};

typedef struct Joueur Joueur;
typedef struct Balle Balle;

pvr_ptr_t joueur_1;
pvr_ptr_t joueur_2;
pvr_ptr_t balle;

Balle balle_st;
Joueur joueur1;
Joueur joueur2;
void SDL_Balle() ;
void SDL_Joueur();



typedef struct{
     int x, y;
     int w, h;
} Rect;
 
Rect position;  

int score_1 = 0;
int score_2 = 0;

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



FG_InitPvr();
uint8 c;
cont_cond_t cond;
c=FG_InitPad();


joueur_1 = pvr_mem_malloc(16*64*2);
png_to_texture("/rd/barre.png", joueur_1, PNG_FULL_ALPHA);

joueur_2 = pvr_mem_malloc(16*64*2);
png_to_texture("/rd/barre_b.png", joueur_2, PNG_FULL_ALPHA);

balle = pvr_mem_malloc(16*16*2);
png_to_texture("/rd/balle.png", balle, PNG_FULL_ALPHA);




//On initialise les psition des joueurs et la balle
joueur1.x = 10;
joueur1.y = 200;
joueur2.x = 620;
joueur2.y = 200;

balle_st.x = 320;
balle_st.y = 240;
//on initialise l'accélération de la balle
balle_st.accx = 8;
balle_st.accy = -8;


while (1)
{if (cont_get_cond(c, &cond) < 0) {
break;
}
if (!(cond.buttons & CONT_START))
break;
if (!(cond.buttons & CONT_DPAD_UP))
{
joueur1.y -= 16;
if (joueur1.y < 0) joueur1.y = 0;
}
     
    if (!(cond.buttons & CONT_DPAD_DOWN))
{
joueur1.y += 16;
if (joueur1.y > 480-64) joueur1.y = 480-64;

};

if (!(cond.buttons & CONT_Y))
{
joueur2.y -= 16;
if (joueur2.y < 0) joueur2.y = 0;
}

if (!(cond.buttons & CONT_A))
{
joueur2.y += 16;
if (joueur2.y > 480-64) joueur2.y = 480-64;
}

if(!(cond.buttons & CONT_B))
{


};

SDL_Balle();
BeginScene();

SDL_Jeu();
EndScene();


};


}

void SDL_Joueur(){

if(up1 & !down1 & joueur1.y >= 2) joueur1.y-=20;
if(!up1 & down1 & joueur1.y <= 420) joueur1.y+=20;
if(up2 & !down2  & joueur2.y >= 2) joueur2.y-=20;
if(!up2 & down2 & joueur2.y <= 420) joueur2.y+=20;
}


int SDL_Jeu(){

  //on affichhe pas toutes les images


//On remet à zéero le nombre de  fps
   

//on affiche les scores


//On positionne le fps
position.x = 250;
position.y = 20;
//SDL_BlitSurface(frame_aff,NULL,ecran,&position);

//On positionne le joueur1 suivnat les coordonnées
position.x = joueur1.x;
position.y = joueur1.y;
FG_DrawImg(16,64,joueur1.x,joueur1.y,1, joueur_1);


//On ajoute le joueur2 suivnat les coordonnées
position.x = joueur2.x;
position.y = joueur2.y;
FG_DrawImg(16,64,joueur2.x, joueur2.y ,1, joueur_2);

//on pose la ballle
position.x = balle_st.x;
position.y = balle_st.y;
FG_DrawImg(16,16,balle_st.x,balle_st.y ,1, balle);

//On ajoute les scores
position.x = 100;
position.y = 20;
//SDL_BlitSurface(score1,NULL, ecran,&position);
position.x =470;



return 0;
}



void SDL_Balle() {
//on bouge les joueurs

if (mouvement_balle == 0) {

//on rélise les teste sur la balle
//en bas et en haut
if(balle_st.y > height - 10 | balle_st.y< 5)
{

balle_st.accy = -balle_st.accy;


}
//on teste si près du joueur 1
if ( abs(balle_st.y - joueur1.y) < 50 & balle_st.x < 20) {

balle_st.accx = -balle_st.accx;
}
if ( abs(balle_st.y - joueur2.y) < 50 & balle_st.x > (width-30)) {

balle_st.accx = -balle_st.accx;
}

//On teste si le joueuer de gauche a perdu
if (balle_st.x < 0) {

mouvement_balle = 0;
score_2++;
balle_st.x = 320;
balle_st.y = 240;
}

if (balle_st.x > width) {

mouvement_balle = 0;
score_1++;
balle_st.x = 320;
balle_st.y = 240;
}

//on bouge la balle

balle_st.y+=balle_st.accy;
balle_st.x+=balle_st.accx;



}






}

voici la lib.c

/*-------------------------------------------   */

/*Frog.c                                        */

/*Date: 11/11/2006                              */

/*Auteur: Olivier NOUGUIER                      */

/*-------------------------------------------   */

#define DEBUG 1

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>



#include <kos.h>

#include <png/png.h>

#include <oggvorbis/sndoggvorbis.h>





#include "frog.h"



uint8 c;

cont_cond_t cond;



extern uint8 romdisk[];

KOS_INIT_ROMDISK(romdisk);



int FG_InitPad(){

c = maple_first_controller();

return c;

};



//Fonction de résolution de l'écran

void FG_InitVideo(int vid){

if (vid==0){

    vid_set_mode(DM_320x240, PM_RGB565);

    }

if (vid==1){

   vid_set_mode(DM_640x480,PM_RGB565);

}

    };

//Fonction d'initialisation du PVR (Obligatoire)

void FG_InitPvr(){
/*-------------------------------------------   */

/*Frog.c                                        */

/*Date: 11/11/2006                              */

/*Auteur: Olivier NOUGUIER                      */

/*-------------------------------------------   */

#define DEBUG 1

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>



#include <kos.h>

#include <png/png.h>

#include <oggvorbis/sndoggvorbis.h>





#include "frog.h"



uint8 c;

cont_cond_t cond;



extern uint8 romdisk[];

KOS_INIT_ROMDISK(romdisk);



int FG_InitPad(){

c = maple_first_controller();

return c;

};



//Fonction de résolution de l'écran

void FG_InitVideo(int vid){

if (vid==0){

    vid_set_mode(DM_320x240, PM_RGB565);

    }

if (vid==1){

   vid_set_mode(DM_640x480,PM_RGB565);

}

    };

//Fonction d'initialisation du PVR (Obligatoire)

void FG_InitPvr(){

    pvr_init_defaults();

    };



void FG_InitTexture(char *where,pvr_ptr_t texture_name,int size_x,int size_y)

{

texture_name = pvr_mem_malloc(size_x*size_y*2);

png_to_texture(where, texture_name,PNG_FULL_ALPHA);

};

   

/*float FG_Fade(float fade_level){

return fade_level;

};



float FG_Fade(){

return 255.0f;

};*/



void FG_InitImg(){};// Fonction permettant d'afficher une image prend comme argument



void FG_DrawImg(int size_x, int size_y,int pos_x,int pos_y,int pos_z, void *ptr){

   //float x;

   

   pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;

       

   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, size_x, size_y, ptr, PVR_FILTER_BILINEAR);

   cxt.gen.culling = PVR_CULLING_NONE;

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = pos_x;

   vert.y = pos_y;    

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size_x+pos_x;//bkgrdi.x;

   vert.y = pos_y;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = pos_x;

   vert.y = size_y+pos_y;//bkgrdi.y;

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size_x+pos_x;//bkgrdi.x;

   vert.y = size_y+pos_y;//bkgrdi.y;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));

   

    };



void FG_DrawBck(int size_x, int size_y,int pos_x,int pos_y,int pos_z, void *ptr){

   

   pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;



   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, size_x, size_y, ptr, PVR_FILTER_BILINEAR);

   cxt.gen.culling = PVR_CULLING_NONE;

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = 0;

   vert.y = 0;    

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = 640;

   vert.y = pos_y;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = 0;

   vert.y = 480;

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = 640;

   vert.y = 480;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));

   

    };



void   BeginScene(){

    pvr_wait_ready();

    pvr_scene_begin();

    pvr_list_begin(PVR_LIST_TR_POLY);

    //pvr_list_begin(PVR_LIST_OP_POLY);

   //draw_back();

   //pvr_list_finish();

    };

   

void EndScene(){

    pvr_list_finish();

    pvr_scene_finish();

    };

   

/*long fmtl_getTimer()

{

 long sec, msec;

 long time;

 timer_ms_gettime(&sec, &msec);

 time = (sec * 1000) + msec;

 return time;

}  



long timer_beginframe ;

 

void FG_AnimSprite(char* name, int x, int y, float n_images, int size,int pos_x,int pos_y,float time_aff){

 

 static float pos=0.0;

 

   time_aff=time_aff*1000; //on multiplie par mille pour convertir en seconde  

   

   //on choisit la vitesse à laquelle on affiche les images

   if (fmtl_getTimer()>=timer_beginframe + time_aff){

timer_beginframe = fmtl_getTimer();

   pos=pos+1.0/n_images;

   if (pos>=1.0) pos=0.0;

   }

   //on affiche  

   pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;



   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, x, y, name, PVR_FILTER_BILINEAR);

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = pos_x;

   vert.y = pos_y;    

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));    

   



};*/



void FG_ChooseTex(char *name,int x, int y,float n_images, int size, int pos_x, int pos_y,float num_image){



float pos=0.0;



pos=num_image/n_images;



pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;



   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, x, y, name, PVR_FILTER_BILINEAR);

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = pos_x;

   vert.y = pos_y;    

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));    



};



int FG_NumAlea(int min, int max){

return (int) (min + ((float) rand() / RAND_MAX * (max - min + 1)));

}

    pvr_init_defaults();

    };



void FG_InitTexture(char *where,pvr_ptr_t texture_name,int size_x,int size_y)

{

texture_name = pvr_mem_malloc(size_x*size_y*2);

png_to_texture(where, texture_name,PNG_FULL_ALPHA);

};

   

/*float FG_Fade(float fade_level){

return fade_level;

};



float FG_Fade(){

return 255.0f;

};*/



void FG_InitImg(){};// Fonction permettant d'afficher une image prend comme argument



void FG_DrawImg(int size_x, int size_y,int pos_x,int pos_y,int pos_z, void *ptr){

   //float x;

   

   pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;

       

   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, size_x, size_y, ptr, PVR_FILTER_BILINEAR);

   cxt.gen.culling = PVR_CULLING_NONE;

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = pos_x;

   vert.y = pos_y;    

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size_x+pos_x;//bkgrdi.x;

   vert.y = pos_y;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = pos_x;

   vert.y = size_y+pos_y;//bkgrdi.y;

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size_x+pos_x;//bkgrdi.x;

   vert.y = size_y+pos_y;//bkgrdi.y;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));

   

    };



void FG_DrawBck(int size_x, int size_y,int pos_x,int pos_y,int pos_z, void *ptr){

   

   pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;



   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, size_x, size_y, ptr, PVR_FILTER_BILINEAR);

   cxt.gen.culling = PVR_CULLING_NONE;

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = 0;

   vert.y = 0;    

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = 640;

   vert.y = pos_y;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = 0;

   vert.y = 480;

   vert.z = pos_z;

   vert.u = 0.0;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = 640;

   vert.y = 480;

   vert.z = pos_z;

   vert.u = 1.0;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));

   

    };



void   BeginScene(){

    pvr_wait_ready();

    pvr_scene_begin();

    pvr_list_begin(PVR_LIST_TR_POLY);

    //pvr_list_begin(PVR_LIST_OP_POLY);

   //draw_back();

   //pvr_list_finish();

    };

   

void EndScene(){

    pvr_list_finish();

    pvr_scene_finish();

    };

   

/*long fmtl_getTimer()

{

 long sec, msec;

 long time;

 timer_ms_gettime(&sec, &msec);

 time = (sec * 1000) + msec;

 return time;

}  



long timer_beginframe ;

 

void FG_AnimSprite(char* name, int x, int y, float n_images, int size,int pos_x,int pos_y,float time_aff){

 

 static float pos=0.0;

 

   time_aff=time_aff*1000; //on multiplie par mille pour convertir en seconde  

   

   //on choisit la vitesse à laquelle on affiche les images

   if (fmtl_getTimer()>=timer_beginframe + time_aff){

timer_beginframe = fmtl_getTimer();

   pos=pos+1.0/n_images;

   if (pos>=1.0) pos=0.0;

   }

   //on affiche  

   pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;



   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, x, y, name, PVR_FILTER_BILINEAR);

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = pos_x;

   vert.y = pos_y;    

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));    

   



};*/



void FG_ChooseTex(char *name,int x, int y,float n_images, int size, int pos_x, int pos_y,float num_image){



float pos=0.0;



pos=num_image/n_images;



pvr_poly_cxt_t cxt;

   pvr_poly_hdr_t hdr;

   pvr_vertex_t vert;



   pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, x, y, name, PVR_FILTER_BILINEAR);

   pvr_poly_compile(&hdr, &cxt);

   pvr_prim(&hdr, sizeof(hdr));



   vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    

   vert.oargb = 0;

   vert.flags = PVR_CMD_VERTEX;

   

   vert.x = pos_x;

   vert.y = pos_y;    

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 0.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 0.0+pos;

   vert.v = 1.0;

   pvr_prim(&vert, sizeof(vert));

   

   vert.x = size+pos_x;

   vert.y = size+pos_y;

   vert.z = 1.0;

   vert.u = 1.0/n_images+pos;

   vert.v = 1.0;

   vert.flags = PVR_CMD_VERTEX_EOL;

   pvr_prim(&vert, sizeof(vert));    



};



int FG_NumAlea(int min, int max){

return (int) (min + ((float) rand() / RAND_MAX * (max - min + 1)));

}


et la lib.h

/*

Frog.h

*/



void FG_InitVideo(int vid); //initialise vid

void FG_InitPvr(); //initialise pvr

void FG_InitTrTex(int *tex,char texname[]); //initialise texture

void FG_InitOpTex(int *tex,char texname[]);

void FG_InitImg();

void FG_DrawImg(int size_x, int size_y,int pos_x,int pos_y,int pos_z, void *ptr); //dessine image

void BeginScene();

void EndScene();

void FG_AnimSprite(char* name, int x, int y, float n_images, int size,int pos_x, int pos_y,float time_aff);

long fmtl_getTimer() ;

//void FG_InitPad();

void FG_ChooseTex(char *name,int x, int y,float n_images, int size, int pos_x, int pos_y,float num_image);

void FG_DrawBck(int size_x, int size_y,int pos_x,int pos_y,int pos_z, void *ptr);

/*void FG_InitText(char *where,char name[20],int size_x,int size_y);*/

void FG_InitTexture(char *where,pvr_ptr_t texture,int size_x,int size_y);

int FG_InitPad();

int FG_NumAlea(int min,int max);

//float FG_Fade(float fade_value);

/*float FG_Fade();*/

WHEN DISASTERS STRIKE !!!
 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 10/01/2010 15:55:00
Send a private message to Bouz
Je ne comprends pas trop pourquoi il y a plusieurs BeginScene(), j'ai un petit écran et c'est pas facile à suivre.
Normalement, avec un seul begin_scène etun seul wait_ready par cycle, tu devrais avoir une animation fluide... Tu ne fais pas du processing en plus sur certains cycles?

 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 10/01/2010 15:59:26
Send a private message to Bouz
Ça serait cool d'avoir un site pour échanger du code, on pourrait balancer ça plus facilement sur nos DC par câble pour voir ce que ça donne (parce que là, je ne vois pas très bien tes saccades!)

 olivier
 Messages postés : 63
 saucisses
 olivier
  Posté le 10/01/2010 18:32:23
Send a private message to olivier
Donne moi ton @ mail je te donne tout çà !!!
Les *.elf et le source.
Ce serait cool j'aimerais finir ma lib si tu pouvais me donner un coup de main

Olivier

WHEN DISASTERS STRIKE !!!
 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 11/01/2010 22:16:53
Send a private message to Bouz
Je t'ai envoyé ça en MP.
Cool, un début e site communautaire sur le développement sur Dreamcast :-)
Si ça continue, je vais trouver quelqu'un qui veut utiliser mon driver audio, je suis sûr qu'il irait très bien avec ton Pong :-)

 Titemoo
 Messages postés : 328
 choucroutes
  Posté le 12/01/2010 11:08:05
Send a private message to Titemoo
Bouz, je suis sûr que ton driver audio intéresserait du monde, si seulement tu l'avais rendu disponible

 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 12/01/2010 21:40:39
Send a private message to Bouz
Eh mais toi je te l'ai filé et tu n'en as pas voulu :-)))
Quand je serai prêt, je le rendrai public, il me manque encore la possibilité de faire durer un son (pour mon jeu de voitures) mais bon, vu que j'y bosse tous les 6 mois...
Enfin bon, tout ça pour dire que je le rendrai public un jour, quoi. D'ailleurs j'avais posté une démo sur DC-France, hahaha.

 Titemoo
 Messages postés : 328
 choucroutes
  Posté le 13/01/2010 16:45:47
Send a private message to Titemoo
Hey c'est pas vrai, je l'ai toujours ton code ! Je me suis basé dessus pour faire ma file de messages et mon memory manager.

Je pense que si tu rends ton code public, y'aurait moyen de l'intégrer à KOS, à la place de l'autre driver pourri…

Et que veux-tu dire par "faire durer un son" ?

--Message edité par titemoo le 2010-01-13 16:47:22--

 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 13/01/2010 22:10:01
Send a private message to Bouz
C'est gentil...
L'idée, c'est de faire les bruits de moteur. Il faut donc un bruit de moteur d'une seconde et un point de bouclage. Après, il faut pouvoir faire varier la fréquence en fonction de la voiture.
Bref, tout un programme.

 Titemoo
 Messages postés : 328
 choucroutes
  Posté le 14/01/2010 00:08:38
Send a private message to Titemoo
Eh bien pas trop difficile, le DSP permet de faire tout ça facilement. Regarde le fichier "aica_v08.txt", tout ce que tu veux est dedans : tu peux jouer un son en boucle (loop) et tu peux aussi modifier la hauteur du son (pitch).

Il doit y avoir moyen aussi d'intégrer l'écho et la réverbération, ça doit être génial

 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 14/01/2010 22:02:30
Send a private message to Bouz
Ben oui, je l'ai fait pour le décodage du S3M: il faut jouer en rythme des samples en faisant varier le pitch, et le volume.
La difficulté, c'est de câbler ça de manière propre pour que tout se passe bien entre le SH4 et l'AICA :-)

 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 14/01/2010 22:06:45
Send a private message to Bouz
Ah fait, Olivier, j'ai bien reçu ton code, je n'ai pas encore eu le temps de regarder, je vais essayer de brancher la DC ce week-end!

 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 01/03/2010 22:56:50
Send a private message to Bouz
Eh ben j'ai toujours pas branché la DC désolé. Promis, je pense à toi, je vais m'y coller dès que possible. Je manque un peu de temps, mais je languis de voir ce que ça donne!
(et de mettre de la musique et des bruitages dessus )

 Titemoo
 Messages postés : 328
 choucroutes
  Posté le 02/03/2010 00:31:53
Send a private message to Titemoo

Citation :

Je pense que si tu rends ton code public, y'aurait moyen de l'intégrer à KOS, à la place de l'autre driver pourri…




D'ailleurs, ça serait vraiment intéressant de le fusionner avec le driver de streaming de KOS, et on pourrait obtenir un truc tout-en-un smile/hapface01.gif

 Bouz
 Messages postés : 650
 choucroutes + bière
 Bouz
  Posté le 06/03/2010 09:37:59
Send a private message to Bouz
Intégrer le streaming... Tout un programme, je crois que ce n'est pas pour tout de suite, mais je vais y penser (quand j'aurai réglé le point de la lecture d'un échantillon en boucle).


forum Index du forum forumLa programmation forumImage qui bave !!!
Haut
Aller à :
  Ajouter une réponse rapide

Ajouter une réponse rapide