How can I load a PNG?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
_.-noel-._
Posts: 49
Joined: Mon Aug 13, 2007 12:57 am

How can I load a PNG?

Post by _.-noel-._ »

Hi...

For my project, I need to load PNGs.

I have paked the code to load PNG in a Header.

My Header: (bg.h)

Code: Select all

#ifdef __cplusplus
extern "C" {
#endif


#include <malloc.h>
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdio.h>
#include "graphics.h"
#include "framebuffer.h"

void bg&#40;void&#41; &#123;


Image* bg;
bg = loadImage&#40;"bg.png"&#41;;
        while&#40;1&#41;
        &#123;
            blitAlphaImageToScreen&#40;0, 0, 480, 272, bg, 0, 0&#41;;
        &#125;
&#125;
#ifdef __cplusplus
&#125;
#endif
and in my main.c I have included the "bg.h" with

Code: Select all

#include "bg.h"
an I loade the function with

Code: Select all

bg&#40;&#41;;
But when I Start my programm, the LCD is black.

My makefile:

Code: Select all

TARGET = V1.0
OBJS = main.o graphics.o framebuffer.o

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = V1.0
LIBS = -lpspgu -lpng -lz -lm -lpspumd -lpspusb -lpspusbstor -lpspctrl
PSPSDK= D&#58;\pspdev\psp\sdk
include $&#40;PSPSDK&#41;\lib\build.mak
I hope anybody can help me...
Sry for my english
2.6,CRACKED!
Posts: 18
Joined: Thu Jul 26, 2007 9:02 pm

Post by 2.6,CRACKED! »

Did you put the file in the folder?

I always forget to do that, and i solve it by making sure if its there or not. Check
_.-noel-._
Posts: 49
Joined: Mon Aug 13, 2007 12:57 am

Post by _.-noel-._ »

yes, i did....

but must the file also stay at the project folder?

and the code is okay, istn't it?
Sry for my english
Xfacter
Posts: 9
Joined: Wed Feb 28, 2007 10:13 am

Re: How can I load a PNG?

Post by Xfacter »

_.-noel-._ wrote:But when I Start my programm, the LCD is black.
Probably because you have an endless loop that never swaps draw buffers.
2.6,CRACKED!
Posts: 18
Joined: Thu Jul 26, 2007 9:02 pm

Post by 2.6,CRACKED! »

make sure when you call the function you have:

sceDisplayWaitVblankStart();
flipScreen();
_.-noel-._
Posts: 49
Joined: Mon Aug 13, 2007 12:57 am

Post by _.-noel-._ »

yes i have...

okay....now it works, but i have another problem...

The image overwrithe the text...

how can i use the image at background?
Sry for my english
Xfacter
Posts: 9
Joined: Wed Feb 28, 2007 10:13 am

Post by Xfacter »

You need to draw the image, then print the text. What you are doing now is not the proper way to use a background. What you need to do is load your image, then start a game/display loop. In the loop you process whatever needs to be processed, then draw whatever needs to be drawn in the order it needs to be drawn (lowest to highest). Then swap your buffers (i.e., call flipScreen()).
_.-noel-._
Posts: 49
Joined: Mon Aug 13, 2007 12:57 am

Post by _.-noel-._ »

ookkayy...

i haven't understand all...
Sry for my english
Post Reply