Welcome! Log In Create A New Profile

Advanced

How to use the Wii IR as a JPEG Image

Posted by BlueWack 
How to use the Wii IR as a JPEG Image
August 18, 2009 05:27AM
I was on CodeMii.com and I did tutorial 4, and I was wondering how I could change the cursor from a "DOT" to a hand JPEG image. My Code is Below.



#include stdio.h
#include stdlib.h
#include string.h
#include malloc.h
#include ogcsys.h
#include gccore.h
#include wiiuse/wpad.h
#include gcmodplay.h
#include jpeg/jpgogc.h

#include "loop_mod.h"

static u32 *xfb;
static GXRModeObj *rmode;

extern char picdata[];
extern int piclength;

// Wiimote IR
ir_t ir;

// Modplay
static MODPlay play;

void display_jpeg(JPEGIMG jpeg, int x, int y) {
unsigned int *jpegout = (unsigned int *) jpeg.outbuffer;
int i,j;
int height = jpeg.height;
int width = jpeg.width/2;
for(i=0;i<=width;i++)
for(j=0;j<=height-2;j++)
xfb[(i+x)+320*(j+16+y)]=jpegout[i+width*j];
free(jpeg.outbuffer);
}


void BlueWack() {

printf("Developed by BlueWack\n");

}

void Initialise() {

VIDEO_Init();
WPAD_Init();
WPAD_SetVRes(0, 640, 480);
WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);

rmode = VIDEO_GetPreferredMode(NULL);

xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(false);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

AUDIO_Init(NULL);
MODPlay_Init(&play);
}

void DrawHLine (int x1, int x2, int y, int color) {
int i;
y = 320 * y;
x1 >>= 1;
x2 >>= 1;
for (i = x1; i <= x2; i++) {
u32 *tmpfb = xfb;
tmpfb[y+i] = color;
}
}

void DrawVLine (int x, int y1, int y2, int color) {
int i;
x >>= 1;
for (i = y1; i <= y2; i++) {
u32 *tmpfb = xfb;
tmpfb[x + (640 * i) / 2] = color;
}
}

void DrawBox (int x1, int y1, int x2, int y2, int color) {
DrawHLine (x1, x2, y1, color);
DrawHLine (x1, x2, y2, color);
DrawVLine (x1, y1, y2, color);
DrawVLine (x2, y1, y2, color);
}


int main() {

Initialise();

VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_WHITE);

JPEGIMG img;
memset(&img, 0, sizeof(JPEGIMG));
img.inbuffer = picdata;
img.inbufferlength = piclength;
JPEG_Decompress(&img);
Initialise();
display_jpeg(img, 0, 0);

MODPlay_SetMOD(&play, loop_mod);
MODPlay_Start(&play);

printf("\x1b[2;0H");
printf("Press Home to exit\n");

while(1) {

WPAD_ScanPads();
u32 pressed = WPAD_ButtonsDown(0);

// IR Movement
WPAD_IR(0, &ir);

if (pressed & WPAD_BUTTON_HOME) {
MODPlay_Stop(&play);
exit(0);
}

if (pressed & WPAD_NUNCHUK_BUTTON_Z) {

printf("Press Home to exit\n");

}

if (pressed & WPAD_NUNCHUK_BUTTON_C) {
BlueWack(1);

}
DrawBox (ir.x, ir.y, ir.x + 1, ir.y + 1, COLOR_RED);





VIDEO_WaitVSync();
}

return 0;
}



Edited 2 time(s). Last edit at 08/18/2009 07:11AM by BlueWack.
Re: How to use the Wii IR as a JPEG Image
August 18, 2009 04:52PM
I personally don't like the jpeg example, try using a graphics library. For example GRRLIB if ou are using C, and libwiisprite if you are using C++. The current jpeg loading code is very confusing. If you need help, check through some source code, many people use hands for pointers and chances are you can understand one of theres.
Re: How to use the Wii IR as a JPEG Image
August 18, 2009 04:59PM
Try making a bigger box. Maybe you just can't see it?
Re: How to use the Wii IR as a JPEG Image
August 18, 2009 10:39PM
It paints [Blue] on the tv.
Sorry, only registered users may post in this forum.

Click here to login