You are not logged in.

#1 2009-12-09 02:13:36

Marth_010
Member

[RESOLVED] Turning IR into a PNG image

Hi all. I just got started in Wii programing and even more recently switched to this library to work on my programs. I was just wondering what to do with this program I have so far where a .png image is supposed to show up and have it's hotspot at (x-112, y-9). When I try to make it, it gives me these errors about the IR:

main.c
c:/grr/trunk/examples/phoenix/source/main.c: In function 'main':
c:/grr/trunk/examples/phoenix/source/main.c:53: error: 'ir_t' has no member named 'ir'
c:/grr/trunk/examples/phoenix/source/main.c:53: error: request for member 'w' in something not a structure or union
c:/grr/trunk/examples/phoenix/source/main.c:53: error: request for member 'w' in something not a structure or union
c:/grr/trunk/examples/phoenix/source/main.c:54: error: 'ir_t' has no member named 'ir'
c:/grr/trunk/examples/phoenix/source/main.c:54: error: request for member 'h' in something not a structure or union
c:/grr/trunk/examples/phoenix/source/main.c:54: error: request for member 'h' in something not a structure or union


My source code is as follows:

Code:

#include <grrlib.h>

#include <math.h>
#include <stdio.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <stdlib.h>
#include <fat.h>
#include <string.h>
#include <wiiuse/wpad.h>

#include "pictures/hand1.h"

ir_t ir;

 
int main() {
    // Initialise the Graphics & Video subsystem
    
    GRRLIB_texImg *tex_hand1 = GRRLIB_LoadTexture(hand1);
    
    GRRLIB_Init();

    // Initialise the Wiimotes
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);

    WPAD_ScanPads();
    //u32 pressed = WPAD_ButtonsDown(0);
    WPAD_IR(0, &ir);
    
        // Loop forever
    while(1) {

        WPAD_ScanPads();  // Scan the wiimotes
        //wpaddown = WPAD_ButtonsDown(0);
        WPAD_IR(WPAD_CHAN_0, &ir);

        // If [HOME] was pressed on the first Wiimote, break out of the loop
        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)  break ;
        
        GRRLIB_DrawImg(10, 60, tex_hand1, 0, 1, 1, 0xFFFFFFFF);
        
        if(ir.valid)
    {
        float XX = (ir.ir.x / 640 * (640 + tex_hand1.w * 2)) - tex_hand1.w;
        float YY = (ir.ir.y / 480 * (480 + tex_hand1.h * 2)) - tex_hand1.h;
        GRRLIB_DrawImg(XX, YY, tex_hand1, 0, 1, 1, 0xFFFFFFFF);
    }
    else
    {
         // Hide cursor
    }
    
    GRRLIB_texImg *tex_hand1 = GRRLIB_LoadTexture(hand1);
    tex_hand1->offsetx = 112; // This value needs to change
    tex_hand1->offsety = 9; // This value needs to change
    GRRLIB_SetHandle(tex_hand1, tex_hand1->offsetx, tex_hand1->offsety);


        // ---------------------------------------------------------------------
        // Place your drawing code here
        // ---------------------------------------------------------------------

        GRRLIB_Render();  // Render the frame buffer to the TV
      VIDEO_WaitVSync();
    }

    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    GRRLIB_FreeTexture(tex_hand1);

    exit(0);  // Use exit() to exit a program, do not use 'return' from main()
}

Edit: I used this previous help: http://grrlib.santo.fr/forum/viewtopic.php?id=183 and practically copied the code altogether. However, I'm getting an error message involving the IR function:

c:/grr/trunk/examples/phoenix/source/main.c:53: error: 'ir_t' has no member named 'ir'
c:/grr/trunk/examples/phoenix/source/main.c:53: error: request for member 'w' in something not a structure or union
c:/grr/trunk/examples/phoenix/source/main.c:53: error: request for member 'w' in something not a structure or union
c:/grr/trunk/examples/phoenix/source/main.c:54: error: 'ir_t' has no member named 'ir'
c:/grr/trunk/examples/phoenix/source/main.c:54: error: request for member 'h' in something not a structure or union
c:/grr/trunk/examples/phoenix/source/main.c:54: error: request for member 'h' in something not a structure or union

and, for some reason, my png isn't identified at the beginning:

c:/grr/trunk/examples/phoenix/source/main.c:30: error: 'hand1' undeclared (first use in this function)

Last edited by Marth_010 (2009-12-09 03:16:38)

Offline

 

#2 2009-12-09 03:26:23

Crayon
Bad Mother Fucker

Re: [RESOLVED] Turning IR into a PNG image

You are using ir.ir.x and ir.ir.y. There is an extra ir.

The ir_t structure is defined like this:

Code:

typedef struct ir_t {
    struct ir_dot_t dot[4];            /**< IR dots                            */
    ubyte num_dots;                    /**< number of dots at this time        */

    int state;                        /**< keeps track of the IR state        */

    int raw_valid;                    /**< is the raw position valid?         */
    sb_t sensorbar;                    /**< sensor bar, detected or guessed    */
    float ax;                        /**< raw X coordinate                    */
    float ay;                        /**< raw Y coordinate                    */
    float distance;                    /**< pixel width of the sensor bar        */
    float z;                        /**< calculated distance in meters        */
    float angle;                    /**< angle of the wiimote to the sensor bar*/

    int smooth_valid;                /**< is the smoothed position valid?     */
    float sx;                        /**< smoothed X coordinate                */
    float sy;                        /**< smoothed Y coordinate                */
    float error_cnt;                /**< error count, for smoothing algorithm*/
    float glitch_cnt;                /**< glitch count, same                    */

    int valid;                        /**< is the bounded position valid?     */
    float x;                        /**< bounded X coordinate                */
    float y;                        /**< bounded Y coordinate                */
    enum aspect_t aspect;            /**< aspect ratio of the screen            */
    enum ir_position_t pos;            /**< IR sensor bar position                */
    unsigned int vres[2];            /**< IR virtual screen resolution        */
    int offset[2];                    /**< IR XY correction offset            */

} ir_t;

Offline

 

#3 2009-12-10 03:15:39

Marth_010
Member

Re: [RESOLVED] Turning IR into a PNG image

Edits to the EXTREME: Ok, so I read your previous comments on changing the . to -> and that seemed to clear up all of my problems... Until I loaded it onto the Wii. I simple get a DSI error and have to reset my Wii to the homebrew channel. Does anyone know what the problem is?

My current code is as follows...

Code:

#include <grrlib.h>

#include <math.h>
#include <wiiuse/wpad.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <unistd.h>

#include "gfx/hand.h"
#include "gfx/sgodot.h"


ir_t ir;

int main() {

    GRRLIB_texImg *tex_hand = GRRLIB_LoadTexture(hand);

    GRRLIB_texImg *tex_sgodot = GRRLIB_LoadTexture(sgodot);

    GRRLIB_Init();
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
    
    while(1) {

        WPAD_ScanPads();
        u32 pressed = WPAD_ButtonsDown(0);
        WPAD_IR(0, &ir);

        GRRLIB_FillScreen(0x00FFFFFF);

        GRRLIB_DrawImg(10, 60, tex_sgodot, 0, 1, 1, 0xFFFFFFFF);
        
    if(ir.valid){
        float XX = (ir.x / 640 * (640 + tex_hand->w * 2)) - tex_hand->w;
        float YY = (ir.y / 480 * (480 + tex_hand->h * 2)) - tex_hand->h;
        GRRLIB_DrawImg(XX, YY, tex_hand, 0, 1, 1, 0xFFFFFFFF);
    }
    else
    {
         // Hide cursor
    }
    
    GRRLIB_texImg *tex_hand = GRRLIB_LoadTexture(hand);
    tex_hand->offsetx = 112; // This value needs to change
    tex_hand->offsety = 9; // This value needs to change
    GRRLIB_SetHandle(tex_hand, tex_hand->offsetx, tex_hand->offsety);

    if (pressed & WPAD_BUTTON_HOME) {
            break;
        }

    

        GRRLIB_Render();
    }

    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    GRRLIB_FreeTexture(tex_sgodot);
    GRRLIB_FreeTexture(tex_hand);

    return 0;

}

Last edited by Marth_010 (2009-12-10 05:08:37)

Offline

 

#4 2009-12-10 15:02:33

Crayon
Bad Mother Fucker

Re: [RESOLVED] Turning IR into a PNG image

With this code you are allocating memory in a infinite loop (inside the while):

Code:

    GRRLIB_texImg *tex_hand = GRRLIB_LoadTexture(hand);

The problem is that there is limited amount of memory on the Wii smile

Offline

 

#5 2009-12-11 05:33:14

Marth_010
Member

Re: [RESOLVED] Turning IR into a PNG image

Ok,  since this didn't seem to be working I went ahead and simply tried to display one picture on an aqua background for this program... But I can't even do that (the program just goes back to the homebrew channel after a black screen)! This is my code. Any pointers would be GLADLY appreciated. Thanks for all of your work already

Code:

#include <grrlib.h>

#include <math.h>
#include <wiiuse/wpad.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <unistd.h>
#include <fat.h>


#include "gfx/sgodot.h"


ir_t ir;

int main() {

    GRRLIB_texImg *tex_sgodot = GRRLIB_LoadTexture(sgodot);

    GRRLIB_Init();
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
    
    while(1) {

        WPAD_ScanPads();
        u32 pressed = WPAD_ButtonsDown(0);
        WPAD_IR(0, &ir);

        GRRLIB_FillScreen(0x00FFFFFF);

        GRRLIB_DrawImg(10, 60, tex_sgodot, 0, 1, 1, 0xFFFFFFFF);
        
    if (pressed & WPAD_BUTTON_HOME) {
            break;
        }

    GRRLIB_Render();
    }

    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    GRRLIB_FreeTexture(tex_sgodot);
   
    return 0;

}

Last edited by Marth_010 (2009-12-11 05:33:43)

Offline

 

#6 2009-12-11 05:41:33

Crayon
Bad Mother Fucker

Re: [RESOLVED] Turning IR into a PNG image

What type of file is sgodot (png, jpg, bmp)? What size (height and widht)?

Offline

 

#7 2009-12-12 04:45:11

Marth_010
Member

Re: [RESOLVED] Turning IR into a PNG image

It's a jpg 200 x 150. Yeah I can't get this one picture to appear no matter what I do. I used the test_jpg in the examples and that appeared on my program. I tried making it smaller, changing it into a .png... nothing works. Help please!

Edit: I got my hand.png to display as an ir cursor over a white background with your code! The only problem is that I can't go all the way to the right. It disappears a couple cm away from the edge (all other sides it will lead off the screen like any other Wii program)

Last edited by Marth_010 (2009-12-12 06:26:28)

Offline

 

#8 2009-12-12 13:43:32

NoNameNo
Administrator

Re: [RESOLVED] Turning IR into a PNG image

please try to read documentation wink

GX have a restriction, texture have to be Width a mutiply of 4, and Height a multiply of 4 too :

200 -> is
150 -> IS NOT !!!

so you fail !!!

Offline

 

#9 2009-12-12 23:10:05

Marth_010
Member

Re: [RESOLVED] Turning IR into a PNG image

I didn't think the 'multiple of 4' rule mattered for jpgs because the warning doesn't appear when you generate the .c and .h files in WiiBuild. However, I changed the dimensions of the original picture to 300 x 224 jpg and it still won't work! (goes to a black screen for and moment and returns to homebrew channel)

Edit: Yays! I finally got my image to appear on my program! What I did started with the original file. After reading the posts on this thread (http://grrlib.santo.fr/forum/viewtopic.php?pid=1128) I immediately changed the original file to a png. After that, I resized it to a proper width and height (300 x 224). Voila, my image appeared!

Do you guys think it had something to do with a premature "ff d9" before the real end? (I don't know how to check)

This is my code thus far (thanks for all the hard work already!):

Code:

#include <grrlib.h>

#include <math.h>
#include <wiiuse/wpad.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <unistd.h>
#include <fat.h>


#include "gfx/hand.h"
#include "gfx/godot.h"


ir_t ir;

int main() {

    GRRLIB_texImg *tex_hand = GRRLIB_LoadTexture(hand);
    GRRLIB_texImg *tex_godot = GRRLIB_LoadTexture(godot);

    GRRLIB_Init();
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
    
    while(1) {

        WPAD_ScanPads();
        u32 pressed = WPAD_ButtonsDown(0);
        WPAD_IR(0, &ir);

        GRRLIB_FillScreen(0xFFFFFFFF);
        
        GRRLIB_DrawImg(300, 225, tex_godot, 0, 1, 1, 0xFFFFFFFF);
                
    if (pressed & WPAD_BUTTON_HOME) {
            break;
        }

    if(ir.valid){
        float XX = (ir.x / 640 * (640 + tex_hand->w * 2)) - tex_hand->w;
        float YY = (ir.y / 480 * (480 + tex_hand->h * 2)) - tex_hand->h;
        GRRLIB_DrawImg(XX, YY, tex_hand, 0, 1, 1, 0xFFFFFFFF);
    }
    else
    {
         // Hide cursor
    }
    
        tex_hand->offsetx = 62; // This value needs to change
        tex_hand->offsety = 5; // This value needs to change
        GRRLIB_SetHandle(tex_hand, tex_hand->offsetx, tex_hand->offsety);
    
    GRRLIB_Render();
    }

    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    GRRLIB_FreeTexture(tex_godot);
    GRRLIB_FreeTexture(tex_hand);

    return 0;

}

Last edited by Marth_010 (2009-12-13 00:09:26)

Offline

 

#10 2009-12-13 02:54:51

Crayon
Bad Mother Fucker

Re: [RESOLVED] Turning IR into a PNG image

Marth_010 wrote:

Do you guys think it had something to do with a premature "ff d9" before the real end? (I don't know how to check)

Just open the image in a HEX editor. On my side I like UltraEdit, I guess Notepad++ could do it (and it's free).

Offline

 

#11 2009-12-13 03:03:45

Marth_010
Member

Re: [RESOLVED] Turning IR into a PNG image

Thanks for all your help Crayon, and you too NoNameNo. I got a ways to go but I'm gonna keep at it

Offline

 

#12 2009-12-17 00:53:33

Crayon
Bad Mother Fucker

Re: [RESOLVED] Turning IR into a PNG image

Marth_010 wrote:

I didn't think the 'multiple of 4' rule mattered for jpgs because the warning doesn't appear when you generate the .c and .h files in WiiBuild.

WiiBuilder 1.5 fixes this issue, it could be downloaded from http://wiibrew.org/wiki/WiiBuilder

Offline

 

Board footer

Powered by FluxBB