Hi!
I'm learning to develop to PSP (and also learning C) and I want to push one button, and see one image in the display.
I have the image in C, and I've tried to make a function for do it, but I haven't get it.
Can anybody help me with a very simple function?
Thanks.
Bye.
How can I put images in display?
Re: How can I put images in display?
What do you mean with "in C"? Do you have an array of u32 values of your image? Then you could do this:kecC wrote:Hi!
I have the image in C, and I've tried to make a function for do it, but I haven't get it.
Code: Select all
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* Define the module info section */
PSP_MODULE_INFO("PAINTIMAGE", 0, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", (void *) exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
#define PSP_SCREEN_WIDTH 480
#define PSP_SCREEN_HEIGHT 272
#define PSP_LINE_SIZE 512
#define PSP_PIXEL_FORMAT 3
int main(void)
{
int i, x, y, oldButtons;
SceCtrlData pad;
u32* image;
u32* vram = (u32*) (0x40000000 | 0x04000000);
SetupCallbacks();
// some demo image
image = malloc(480*272*4);
for (y = 0; y < 272; y++) {
for (x = 0; x < 480; x++) {
image[x + y*480] = x * y;
}
}
// init graphics
sceDisplaySetMode(0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
sceDisplaySetFrameBuf((void *) vram, 512, 3, 1);
// clear screen
for (i = 0; i < 512 * 480; i++) vram[i] = 0;
// wait for key
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
sceCtrlReadBufferPositive(&pad, 1);
oldButtons = pad.Buttons;
while (1) {
sceDisplayWaitVblankStart();
sceCtrlReadBufferPositive(&pad, 1);
if (oldButtons != pad.Buttons) break;
}
// draw image
for (y = 0; y < 272; y++) {
for (x = 0; x < 480; x++) {
vram[x + y * 512] = image[x + y*480];
}
}
sceKernelSleepThread();
return 0;
}
BTW: with my Lua Player the full source code for the same, but loading a PNG image from memory stick included, looks like this:
Code: Select all
image = loadImage("background.png")
oldButtons = ctrlRead()
while true do
waitVblankStart()
buttons = ctrlRead()
if buttons ~= oldButtons then
break
end
end
blitImage(0, 0, image)
flipScreen()
Thanks a lot!
But I want to show a image like this type:
How can I do it?
Thanks again!
But I want to show a image like this type:
Code: Select all
const unsigned short image[] = {
0x735a,0x6f39,0x6b39,0x6f39,0x6b39,0x6f39,...
}
Thanks again!
Dude, that's what the code he gave you does.kecC wrote:Thanks a lot!
But I want to show a image like this type:
How can I do it?Code: Select all
const unsigned short image[] = { 0x735a,0x6f39,0x6b39,0x6f39,0x6b39,0x6f39,... }
Thanks again!
-
- Posts: 19
- Joined: Tue Jul 05, 2005 7:35 am
Thanks for the samples guys. It worked, but the colors are messed up.
My orginal pic was 24 bit color. Is there something I need to change in the init of the screen buffer?
Thanks.
Hex.
ps.
You know when you used to play Doom too long when you were a kid... and your head felt rather football shaped and there was pain somewhere about a half inch behind your eyes? I have that from reading C primers and PSP samples... but I'm getting there! 8)
My orginal pic was 24 bit color. Is there something I need to change in the init of the screen buffer?
Thanks.
Hex.
ps.
You know when you used to play Doom too long when you were a kid... and your head felt rather football shaped and there was pain somewhere about a half inch behind your eyes? I have that from reading C primers and PSP samples... but I'm getting there! 8)
-
- Posts: 19
- Joined: Tue Jul 05, 2005 7:35 am
I figured it out, but I don't know why it worked. Still reading up on my C.
I changed the define for vram from u32 to u16.
And I changed the PixelMode from 3 to 1 which means that the tool that converted my picture created a 16bit array in the .c file rather than a 32bit array which the sample code above was expecting. (I'm guessing).
This thread was what got me going in the right direction if you are still looking for help with this...
http://forums.ps2dev.org/viewtopic.php?t=2899
Cheers
I changed the define for vram from u32 to u16.
And I changed the PixelMode from 3 to 1 which means that the tool that converted my picture created a 16bit array in the .c file rather than a 32bit array which the sample code above was expecting. (I'm guessing).
This thread was what got me going in the right direction if you are still looking for help with this...
http://forums.ps2dev.org/viewtopic.php?t=2899
Cheers