You are not logged in.

#1 2009-05-04 17:52:56

celinedules
Member

[RESOLVED] Loading images on the fly

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.

Code:

#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

 

#2 2009-05-04 19:56:36

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

Offline

 

#3 2009-05-04 20:51:38

celinedules
Member

Re: [RESOLVED] Loading images on the fly

Okay so I tried that and when I try to run it, it causes my Wii to freeze. Here is my code:

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

 

#4 2009-05-04 21:36:02

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

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

 

#5 2009-05-04 21:49:11

celinedules
Member

Re: [RESOLVED] Loading images on the fly

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:

Code:

GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile("sd:/images/background.png");

Last edited by celinedules (2009-05-04 21:53:44)

Offline

 

#6 2009-05-04 22:12:20

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

Try to add some validation to the function:

Code:

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

 

#7 2009-05-04 22:22:38

celinedules
Member

Re: [RESOLVED] Loading images on the fly

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

 

#8 2009-05-04 22:31:57

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

Are you using libogc 1.7.1: http://www.devkitpro.org ???

Offline

 

#9 2009-05-04 22:41:49

celinedules
Member

Re: [RESOLVED] Loading images on the fly

I tried using that, now I get a bunch of errors saying it can't find fat.h

Offline

 

#10 2009-05-04 22:51:44

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

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

 

#11 2009-05-04 22:54:19

celinedules
Member

Re: [RESOLVED] Loading images on the fly

I fixed that problem but now I get this error

Code:

> "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.

Code:

> "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

 

#12 2009-05-04 23:02:13

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

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

Code:

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

 

#13 2009-05-04 23:05:17

celinedules
Member

Re: [RESOLVED] Loading images on the fly

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

 

#14 2009-05-04 23:14:22

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

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

 

#15 2009-05-04 23:23:08

celinedules
Member

Re: [RESOLVED] Loading images on the fly

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:

Code:

> "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

 

#16 2009-05-04 23:29:54

Crayon
Bad Mother Fucker

Re: [RESOLVED] Loading images on the fly

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

 

#17 2009-05-04 23:52:49

celinedules
Member

Re: [RESOLVED] Loading images on the fly

So I restarted my computer and everything works now. It loads and displays images perfectly.

Thank you for all the help.

Offline

 

Board footer

Powered by FluxBB