You are not logged in.
I know how to convert png images using raw2c but is it possible to load them from an sd card and then display them? I cam up with something like this but when the image displays, it is all garbled.
#include <stdlib.h> #include <wiiuse/wpad.h> #include "GRRLIB/GRRLIB.h" #include "fat.h" Mtx GXmodelView2D; int main() { u32 wpaddown; GRRLIB_Init(); WPAD_Init(); void *imgData; s32 ret; ret = Fat_ReadFile("sdhc:/images/background.png", &imgData); GRRLIB_texImg tex = GRRLIB_LoadTexture(imgData); while(1) { WPAD_ScanPads(); wpaddown = WPAD_ButtonsDown(0); GRRLIB_DrawImg(0, 0, tex, 0, 1, 1, 0xFFFFFFFF); GRRLIB_Render(); if(wpaddown & WPAD_BUTTON_HOME) { exit(0); } } GRRLIB_Exit(); return 0; }
Last edited by celinedules (2009-05-04 18:48:43)
Offline
Check GRRLIB_LoadTextureFromFile:
http://code.google.com/p/grrlib/source/ … IB_addon.c
Offline
Okay so I tried that and when I try to run it, it causes my Wii to freeze. Here is my code:
#include "GRRLIB/GRRLIB.h" #include "GRRLIB/GRRLIB_addon.h" #include <stdlib.h> #include <wiiuse/wpad.h> #include <fat.h> Mtx GXmodelView2D; int main() { u32 wpaddown; GRRLIB_Init(); GRRLIB_addon_Init(); WPAD_Init(); GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile("sd:/images/background.png"); while(1) { WPAD_ScanPads(); wpaddown = WPAD_ButtonsDown(0); GRRLIB_DrawImg(0, 0, tex, 0, 1, 1, 0xFFFFFFFF); GRRLIB_Render(); if(wpaddown & WPAD_BUTTON_HOME) { exit(0); } } GRRLIB_Exit(); return 0; }
Last edited by celinedules (2009-05-04 21:22:06)
Offline
Are you using the version of GRRLIB from the svn repository?
If not, I think in the old version (the you could download on the main page) the third parameter of GRRLIB_DrawImg was not a pointer.
So try:
GRRLIB_DrawImg(0, 0, *tex, 0, 1, 1, 0xFFFFFFFF);
or
GRRLIB_DrawImg(0, 0, &tex, 0, 1, 1, 0xFFFFFFFF);
or comment the line to see if it crash without this line
//GRRLIB_DrawImg(0, 0, tex, 0, 1, 1, 0xFFFFFFFF);
Offline
I am using the version from the repository and so I thought I would just try and comment out the GRRLIB_DrawImg function and it still freezes. So I don't even think it's getting to that point.
edit: So it's this line that causes it to freeze:
GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile("sd:/images/background.png");
Last edited by celinedules (2009-05-04 21:53:44)
Offline
Try to add some validation to the function:
GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename) { GRRLIB_texImg *tex = NULL; fatInitDefault(); FILE *fd = fopen(filename, "rb"); if(fd != NULL) { fseek(fd, 0, SEEK_END); long lsize = ftell(fd); rewind(fd); unsigned char *buffer = (unsigned char*) malloc (sizeof(unsigned char)*lsize); if(buffer) { fread (buffer, 1, lsize, fd); tex = GRRLIB_LoadTexture(buffer); free(buffer); } fclose(fd); } return tex; }
PS: the code was not tested
Offline
So now it doesn't freeze but why won't it load the image (I have tried several even the ones from the examples). The correct path to the memory card is "sd:/" right? I tried "sdhc:/" also but with no luck.
Offline
Are you using libogc 1.7.1: http://www.devkitpro.org ???
Offline
I tried using that, now I get a bunch of errors saying it can't find fat.h
Offline
If you are using devkitPro on Windows you should be using the Windows Installer: http://sourceforge.net/project/showfile … _id=160396
If that's what you did, could you give more information about the errors you are having.
Offline
I fixed that problem but now I get this error
> "make" linking ... boot.elf c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-gekko/4.2.3/../../../../powerpc-gekko/bin/ld.exe: cannot find -lpng collect2: ld returned 1 exit status make[1]: *** [/c/WiiProjects/grrlib_template/boot.elf] Error 1 "make": *** [build] Error 2 > Process Exit Code: 2 > Time Taken: 00:00
I get it from time to time but I don't ever remember how I fixed it.
Okay so I copied the libpng.a into the lib folder but now when I compile I get a popup error saying ld.exe has stopped working.
> "make" linking ... boot.elf collect2: ld returned 5 exit status make[1]: *** [/c/WiiProjects/grrlib_template/boot.elf] Error 1 "make": *** [build] Error 2 > Process Exit Code: 2 > Time Taken: 00:03
Last edited by celinedules (2009-05-04 23:01:11)
Offline
In your Makefile, put the path to your lib folder on line LIBDIRS.
Or move all your.a files to C:\devkitPro\libogc\lib\wii
GRRLIB := ../../GRRLIB TARGET := $(notdir $(CURDIR)) BUILD := build SOURCES := source source/gfx $(GRRLIB)/GRRLIB $(GRRLIB)/lib/libpng/pngu DATA := data INCLUDES := ............. #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- LIBDIRS := $(CURDIR)/$(GRRLIB)
Offline
I did move them to C:\devkitPro\libogc\lib\wii but thats when I got the error that ld.exe has stopped working.
BTW I appreciate all the help
Offline
Try to clear the compile code with one of these steps:
* Alt + 2 in Programmer's Notepad
* delete the build folder
* type in your Makefile folder: make clean
Offline
I had already tried that so I thought I would reinstall devkitPro with the latest version. Now I can't even compile an empty project. I get the error:
> "make" main.c powerpc-gekko-gcc.exe: CreateProcess: No such file or directory make[1]: *** [main.o] Error 1 "make": *** [build] Error 2 > Process Exit Code: 2 > Time Taken: 00:00
Offline
Maybe the Environment Variables are not set properly. So this folder is not in the path for compilation : C:\devkitPro\msys\bin
Try rebooting your PC and check Control Panel - System - Advanced - Environment Variables
Offline
So I restarted my computer and everything works now. It loads and displays images perfectly.
Thank you for all the help.
Offline