Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ya2d sample by xerpi */
- #include <pspkernel.h>
- #include <pspctrl.h>
- #include <pspdisplay.h>
- #include <pspdebug.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <time.h>
- #include <pspgu.h>
- #include <pspgum.h>
- #include <vram.h>
- #include <tinyfont.h>
- #include <ya2d.h>
- PSP_MODULE_INFO("ya2d Sample", 0, 1, 1);
- PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
- /* Exit callback */
- int exit_callback(int arg1, int arg2, void *common)
- {
- return 0;
- }
- /* Callback thread */
- int CallbackThread(SceSize args, void *argp)
- {
- int cbid;
- cbid = sceKernelCreateCallback("Exit Callback", 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;
- }
- int main(int argc, char* argv[])
- {
- // srand(time(NULL));
- SetupCallbacks();
- sceCtrlSetSamplingCycle(0);
- sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
- ya2d_init();
- struct ya2d_texture *t;
- t = ya2d_load_PNG_file("test3.png", YA2D_PLACE_VRAM);
- if (t == NULL) goto exit;
- struct ya2d_texture *c;
- c = ya2d_load_PNG_file("test4.png", YA2D_PLACE_VRAM);
- if (c == NULL) goto exit;
- ya2d_swizzle_texture(t);
- float angle = 0.0f;
- float cross_x = 50, cross_y = 50;
- SceCtrlData pad, old_pad; old_pad.Buttons = 0;
- int centered = 0, rotate = 0, vsync = 0;
- unsigned char trans = 0;
- ya2d_set_vsync(1);
- struct ya2d_camera *CAMERA;
- //we center camera on the screen
- CAMERA = ya2d_init_camera(240.0f, 136.0f, 4.0f, 1.0f, 1.0f);
- if(CAMERA == NULL) goto exit;
- while(1)
- {
- sceCtrlPeekBufferPositive(&pad, 1);
- ya2d_start_drawing();
- ya2d_clear_screen(0);
- if (pad.Buttons & PSP_CTRL_RTRIGGER) angle += 0.005f;
- else if (pad.Buttons & PSP_CTRL_LTRIGGER) angle -= 0.005f;
- if (pad.Buttons & PSP_CTRL_CROSS & ~old_pad.Buttons) centered = !centered;
- if (pad.Buttons & PSP_CTRL_TRIANGLE & ~old_pad.Buttons) rotate = !rotate;
- if (pad.Buttons & PSP_CTRL_SQUARE & ~old_pad.Buttons) ya2d_set_vsync(vsync = !vsync);
- if (pad.Buttons & PSP_CTRL_RIGHT) {
- if (trans < 255) trans++;
- }
- if (pad.Buttons & PSP_CTRL_LEFT) {
- if (trans > 0) trans--;
- }
- if (fabs(pad.Lx-128) > 60) CAMERA->x += CAMERA->speed * (pad.Lx-128)/100.0f;
- if (fabs(pad.Ly-128) > 60) CAMERA->y += CAMERA->speed * (pad.Ly-128)/100.0f;
- ya2d_draw_pixel(NULL, 16, 16, 0xFFFFFFFF);
- ya2d_draw_pixel(CAMERA, 16, 16, 0xFFFFFFFF);
- /*
- EQUIVALENT OF
- ya2d_draw_texture_scale(t, cross_x, cross_y, 0.5f, 0.5f);
- */
- // ya2d_draw_texture_scale_size_defined(t, cross_x, cross_y, 128, 128);
- /*
- DRAW GRID FROM
- CAMERA (NULL if we want draw on screen)
- START X (UP LEFT COORD)
- START Y (UP LEFT COORD)
- SIZE OF A CASE FROM GRID IN X
- SIZE OF A CASE FROM GRID IN Y
- NUMBER OF CASES X
- NUMBER OF CASES Y
- LINE SIZE
- COLOR
- */
- ya2d_draw_grid(NULL, 4, 4, 32, 32, 4, 4, 1, 0xFFFFFFFF);
- ya2d_draw_grid(CAMERA, 136, 136, 4, 4, 4096, 4096, 1, 0xFF0000FF);
- ya2d_draw_grid_centered(CAMERA, 100, 100, 32, 32, 4, 4, 8, 0xFF0000FF);
- int i;
- char l = 'A';
- int x = 2;
- for(i = 40; i >= 8; i -= 2)
- {
- tinyfont_draw_stringf(x, 2, i, GU_RGBA(0,0,255,255), "%c ", l);
- l++;
- x += i;
- }
- tinyfont_draw_stringf(10, 272-20, 10, GU_RGBA(0,0,255,255), "FPS: %.2f, camera coord = {%d,%d}", ya2d_get_fps(), (int)CAMERA->x, (int)CAMERA->y);
- // tinyfont_set_size(8);
- // tinyfont_draw_stringf(12, 30, GU_RGBA(0,0,255,255), "x: %.2f | y: %.2f", cross_x, cross_y);
- // if (centered) tinyfont_draw_string(265, 42, GU_RGBA(255,0,255,255), "centered");
- // if (rotate) tinyfont_draw_string(265, 54, GU_RGBA(0,255,255,255), "rotate");
- // if (vsync) tinyfont_draw_string(265, 66, GU_RGBA(255,0,0,255), "vsync");
- // tinyfont_draw_string16x16(10, 60, GU_RGBA(35,153,45,255), "16x16 Draw test!");
- tinyfont_draw_rotated_string(240, 136, 12, GU_RGBA(255,255,0,255), angle, "Rotated text!!");
- ya2d_finish_drawing();
- ya2d_swapbuffers();
- ya2d_calc_fps();
- old_pad = pad;
- }
- ya2d_free_texture(t);
- exit:
- ya2d_shutdown();
- sceKernelExitGame();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement