miércoles, 9 de septiembre de 2009

[Tutorial C] Escribiendo sobre una imagen

este tuto os enseñare a escribir sobre una imagen y usar una Font en este ejemplo la comic sanc en negrita
es muy sencillo pero es fundamental para un homebrew
---------------------------------------------------------------
Descarga las librerias y el main.c y el makefile: http://rapidshare.com/files/277632094/escribir_sobre_imagenes_y_usar_fuente_en__C__by_tete67.rar.html
---------------------------------------------------------------
MAIN.C

/*Escribir sobre imagenes */
/*Autor: TeTe67 */
/*Fecha: 09/9/2009 */
//Librerias necesarias
#include <>// juntamos los < > de las librerias porque las tengo que separar si no no aparecen ;)
#include < pspdebug.h >
#include < pspkernel.h >
#include < png.h >
#include < pspgu.h >
#include < pspdisplay.h >
#include < pspgum.h >
#include < stdio.h >
#include "fontloader.h"//Esta es en la libreria que nos fijaremos
#include "graphics.h"//para mostrar Graficos (Imagenes)

PSP_MODULE_INFO("Escribir sobre imagenes Sample", 0 , 1 , 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

Image* img;//damos valores a la IMG
Font* let;//Damos valores a la Font (Letras)
//CallBacks (Sirve para hacer funcionar el boton Home)
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp)
{
int cbid;

cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);

sceKernelSleepThreadCB();

return 0;
}
int SetupCallbacks(void)
{
int thid = 0;

thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}

return thid;
}
//Fin Callbacks

//Empieza el Main
int main()//Fucion principal
{//abrimos para definir
pspDebugScreenInit();//Inicia la pantalla en modo debug
initGraphics();//Inicia los graficosz
SetupCallbacks();//Inicia las CallBacks
char buffer[200];//Crea un buffer de 200 mas no poruqe no hace falta
sprintf(buffer, "Imagen.png");//Indicamos imagen para que la cargue
img = loadImage(buffer); //Imagen almacenada en el buffer
sceDisplayWaitVblankStart();
blitAlphaImageToScreen(0 ,0 ,480 , 272, img, 0, 0); //Colocamos la imagen en pantalla con las coordenadas
flipScreen();// le damos la vuelta a la pantalla
let=Font_Load("fuente.ttf");//Carga la fuente font.ttf en el puntero let
Font_SetSize(let ,20);//Establece el tamaño de let

while(1)//abre bucle
{//Abre para hacer las funciones
blitAlphaImageToScreen(0 ,0 ,480 , 272, img, 0, 0);
Font_Print_Image(let, 20, 50, "El sample ha funcionado con Exito", GU_RGBA(255, 255, 0, 255 ), img);//Imprime encima de la imagen con la fuente let en color verde sobre la imagen img
Font_Print_Image(let, 100, 200, "[www.todopsp.com]", GU_RGBA(255, 255, 0, 255 ), img);
sceDisplayWaitVblankStart();
flipScreen();//Le da la vuelta a la pantalla
}//Cierra el bucle
sceKernelSleepThread();//te lo deja en modo suspension
return 0;//Si todo a funcionado vien te dara un retornara a un 0
}//Cierra el Main y acaba todo a COMPILAR![/code]

---------------------------------------------------------------
MAKEFILE


[code]TARGET = Font_Tete67
OBJS = main.o graphics.o framebuffer.o fontloader.o

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP

LIBS = -lpspgu -lpng -lz -lm -lpspdisplay -lpspgum -lfreetype

PSP_EBOOT_TITLE = Escribir sobre imagenes Sample

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

No hay comentarios:

Publicar un comentario