You are not logged in.

#1 2008-07-10 19:20:35

aquilino
Member

GRRLIB_Printf

I have a problem with GRRLIB_Printf,

within the Main

I u8 * text_font1 etc. .....

But outside the main as I put it

I put u8 * text_font1 and gives error

thanks

Offline

 

#2 2008-07-11 05:23:35

Crayon
Bad Mother Fucker

Re: GRRLIB_Printf

Could you put more code. Like, perhaps, the part with the GRRLIB_LoadTexture funtion.

Offline

 

#3 2008-07-12 15:46:01

aquilino
Member

Re: GRRLIB_Printf

before using it with 1.6:

GRRLIB_Printf(55,60 + font3_char_high*line,font3_char_width,font3_char_high,text,font3,fgcolor,bgcolor);

Now it is not with 3.01a

thanks for the help

Code:

/*===========================================
   GRRLIB Template
   Use this to start coding with GRRLIB!
===========================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <fat.h>
#include <sys/dir.h>
#include <unistd.h>
#include <mp3player.h>
#include "GRRLIB/GRRLIB.h"

//include our fonts to use within the printfunction!
#include "GRRLIB/fonts/GRRLIB_font1.h"
//#include "GRRLIB/fonts/font3.h"
#include "gfx/menu.h"
//#include "gfx/logo.h"
#include "gfx/cursor.h"

#define clrscr() GRRLIB_FillScreen(0x00000000)
#define WHITE 0xFFFFFFFF
#define BLACK 0x00000000
u16 color = 0x0000;
extern u16 *GRRLIB_buffer;

char filename[MAXPATHLEN]; // always guaranteed to be enough to hold a filename

//Files
FILE* pFile;
long lSize;
char * buffer;
size_t result;
   
int fcount = 0;
int i = 0;

int rot = 0;
char files[1000][80]; //1000 files with 80 chars
char *file = "";

Mtx GXmodelView2D;
int main(){
   //u8 *tex_font3 = GRRLIB_LoadTexture (font3) ;
   u8 *tex_font1=GRRLIB_LoadTexture(GRRLIB_font1),
       //*tex_logo=GRRLIB_LoadTexture(logo),
       *tex_menu=GRRLIB_LoadTexture(menu),
       *tex_cursor=GRRLIB_LoadTexture(cursor);
     
struct point{
   int x;
   int y;
} cursor;



WPADData *wpaddata;

void GetFiles(void)
{
fcount= 0;
//##########################################################
//Show all files in directory
//Open directory
//clrscr();

struct stat st;
DIR_ITER* dir;
dir = diropen ("/mp3/");

if (dir == NULL) //If empty
   {
   //printf (" Unable to open the directory.\n");
   GRRLIB_Printf(50,50,tex_font1,0xFFFFFFFF,1," Unable to open the directory.");
   }
   else
   {
   while (dirnext(dir,filename,&st) == 0)
      {
      if ((st.st_mode & S_IFDIR ? 1 : 0)== 0)
         {
         // st.st_mode & S_IFDIR indicates a directory
         strcpy(files[fcount], filename);
         ++fcount;   
         }
      }
   }   
   
}
   
void SelectFile(int iSelected)
   {
   int x;
   
   for (x=0;x!=fcount;x++)
      {
      if (x==iSelected)
         {
         GRRLIB_Printf( 55, 60, tex_font1, 0xFFFFFFFF, 1, files[x]);
         }
         else
         {
         GRRLIB_Printf( 55, 60, tex_font1, 0x00000000, 1, files[x]);
         }
      }
}

   fatInitDefault();
   
   //GRRLIB_buffer=(u16 *)malloc(640*480*2);
   
   VIDEO_Init();
   WPAD_Init();
   WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
   WPAD_SetVRes(WPAD_CHAN_0, 640, 480);
   WPAD_SetIdleTimeout(180); 

   
   GRRLIB_InitVideo();
   GRRLIB_Start();
   GRRLIB_FillScreen(0x0000);     
   GRRLIB_Render();
   VIDEO_WaitVSync();

   cursor.x=0;
   cursor.y=0;
   
   GetFiles();
   // SelectFile(0);
     
   while(1){
     GRRLIB_FillScreen(0xFF000000);
    
      WPAD_ScanPads ();
      //Draw Cursor and calculate coordinates
      ir_t  ir;
      orient_t orient;
     
      WPAD_IR(WPAD_CHAN_0, &ir);
      WPAD_Orientation(WPAD_CHAN_0, &orient);

      int ha = (int)orient.roll;
      if(ha<0){ha=360+ha;}
    
      float rad_angle = 2.0*3.14159*ha/360.0;
      float corrected_rad_angle = 2.0*3.14159*(ha-45.0)/360.0;
      float px = ir.x+8.0+sin(corrected_rad_angle)*8.0*1.41;
      float py = ir.y+8.0-cos(corrected_rad_angle)*8.0*1.41;
      cursor.x=round(px);
      cursor.y=round(py);     

 /*  char cursorx_text[8];
     char cursory_text[8];
   
   
  //para ver las coordernadas del cursor
   sprintf(cursorx_text, "%d", cursor.x);
   sprintf(cursory_text, "%d", cursor.y);
   GRRLIB_Print(50,350,font3_char_width,font3_char_high,cursorx_text,font3,0xffff,0xf01e);
    GRRLIB_Print(50,360,font3_char_width,font3_char_high,cursory_text,font3,0xffff,0xf01e);*/
      
       //comprobamos si el cursor esta encima de algun fichero
       if(cursor.x >= 20 && cursor.x<=310 && cursor.y >=50 && cursor.y <=50+(19)*(fcount))
        {
           
     /* GRRLIB_Print(50,400,font3_char_width,font3_char_high,"  cursor ...",font3,0xffff,0xf01e);*/
        i=(int)((cursor.y-50)/19);
        SelectFile(i); 
      }

      //pinto el menu play list
     GRRLIB_DrawImg(0,0, 640, 480, tex_menu,0, 1, 1, 255 ); 
     SelectFile(i);   
     //pinto el cursor
     GRRLIB_Plot(ir.x,ir.y, BLACK);
     GRRLIB_DrawTile(ir.x, ir.y, 21, 31, tex_cursor,rad_angle, 1, 1, 255,1,1 );       
          
      if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A)
      {//open file and load in memory
         
      char path[100] = "/mp3/";
      file = files[i];
      strcat(path,file);
     
      if (file != NULL)
         {
       clrscr();
       //pinto el menu mp3 player
       GRRLIB_DrawImg(0,0, 640, 480, tex_menu,0, 1, 1, 255 );

       
       GRRLIB_Printf(55,60,tex_font1,0x00000000,1,file);
       GRRLIB_Printf(55,400,tex_font1,0x00000000,1,"Pulsa B para parar ...");
          
      GRRLIB_Render();
      VIDEO_WaitVSync();
     
   
         pFile = fopen (path, "r");
     
         //Check that pFile exist
         if (pFile!=NULL)
            {   
            // obtain file size:
            fseek (pFile , 0 , SEEK_END);
            lSize = ftell (pFile);
            rewind (pFile);

            // allocate memory to contain the whole file:
            buffer = (char*) malloc (sizeof(char)*lSize);
            if (buffer == NULL) {fputs ("   Memory error",stderr); exit (2);}

            // copy the file into the buffer:
            result = fread (buffer,1,lSize,pFile);
            if (result != lSize) {fputs ("   Reading error",stderr); exit (3);}

            /* whole file is now loaded in the memory buffer*/
           // clrscr();
            printf("   %s loaded\n",path);
            fclose (pFile);
            }
         else if (pFile==NULL)
            {
         
            printf("   File error");
            fclose (pFile);
            //exit (0);
            GetFiles();
            }
         } else GetFiles();
     
      if (buffer != NULL)
      {
      MP3Player_Init();
      /*** Play from memory ***/
      MP3Player_PlayBuffer(buffer,lSize,NULL)   ; //ToDo: Replace with MP3Player_PlayFile() ?
      /*** Play to end... ***/
      printf ("\n\n");
      printf("   Playing %s\n",file);
    
  while (MP3Player_IsPlaying())
         {
   clrscr();
    WPAD_ScanPads (0);
    wpaddata = WPAD_Data(0);   //donĀ“t work ?
   
    if(WPAD_ButtonsDown(0) & WPAD_BUTTON_B)
           {   
            MP3Player_Stop();
            }  
         }
       // terminate
        fclose (pFile);
        free (buffer);
      }
      SelectFile(i);
      }
     
      GRRLIB_Render();
      VIDEO_WaitVSync();
     
      if (WPAD_ButtonsDown (0) & WPAD_BUTTON_HOME)
      {
            GRRLIB_FillScreen(0x00000000);   //borramos el buffer ahora en negro ;)

            //imprime el mensaje al buffer
            GRRLIB_Printf (280,200,tex_font1,0xffffffff,1,"  saliendo ...");
            
            //saca el buffer por pantalla
            GRRLIB_Render ();
            VIDEO_WaitVSync();
            
            //sale al HBC
            exit(0);
      }
    }

return(0);

}

src is minimp3player

I have upgraded to 3.01a

but it fails

Last edited by aquilino (2008-07-12 15:52:26)

Offline

 

#4 2008-07-12 19:35:04

Crayon
Bad Mother Fucker

Re: GRRLIB_Printf

It's not a case of GRRLIB does not work, it's a case of I don't know how to program in C.

It's normal that tex_font1 could not be used out the Main function. It's declare in the Main function. If you want it to be accessible outside you need to put it ouside the Main like others globals variables.

Code:

   u8 *tex_font1=GRRLIB_LoadTexture(GRRLIB_font1),
       //*tex_logo=GRRLIB_LoadTexture(logo),
       *tex_menu=GRRLIB_LoadTexture(menu),
       *tex_cursor=GRRLIB_LoadTexture(cursor);

int main(){

For more info: http://en.wikipedia.org/wiki/Global_variable

Offline

 

#5 2008-07-12 21:20:10

aquilino
Member

Re: GRRLIB_Printf

is a thing not to question enteder

I had to put everything outside the main to operate within the main

if you put your

u8 * tex_font1 = GRRLIB_LoadTexture (GRRLIB_font1)
and within the main outside not compiles

Offline

 

#6 2008-07-13 00:29:48

Crayon
Bad Mother Fucker

Re: GRRLIB_Printf

I mean more something like this:

Code:

u8 *tex_font1,
   //*tex_logo,
   *tex_menu,
   *tex_cursor;

int main(){
   tex_font1 = GRRLIB_LoadTexture(GRRLIB_font1);
   //tex_logo = GRRLIB_LoadTexture(logo);
   tex_menu = GRRLIB_LoadTexture(menu);
   tex_cursor = GRRLIB_LoadTexture(cursor);

If there is an error with the compiler you should always post it, it's easier for everyone to help you.

Last edited by Crayon (2008-07-13 00:33:50)

Offline

 

Board footer

Powered by FluxBB