From c0ababb4e44a5cb6ef451e9e95f6d5c5c592ba7d Mon Sep 17 00:00:00 2001 From: N0NameN0 Date: Wed, 4 Feb 2009 21:46:11 +0000 Subject: [PATCH] [NEW] GRRLIB_GetPixelFromtexImg and GRRLIB_SetPixelTotexImg !!!! BUGGED DO NOT USE until working ;) !!! --- README.TXT | 6 ++-- template/source/GRRLIB/GRRLIB.c | 52 ++++++++++++++++++++++++++++++ template/source/GRRLIB/GRRLIB.h | 3 ++ template/source/gfx/pixeltest.c | 20 ++++++++++++ template/source/gfx/pixeltest.h | 14 ++++++++ template/source/gfx/pixeltest.png | Bin 0 -> 183 bytes template/source/main.c | 17 ++++++++++ 7 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 template/source/gfx/pixeltest.c create mode 100644 template/source/gfx/pixeltest.h create mode 100644 template/source/gfx/pixeltest.png diff --git a/README.TXT b/README.TXT index 039079c..2064a16 100644 --- a/README.TXT +++ b/README.TXT @@ -51,8 +51,10 @@ ChangeLog : * InitVideo() and GRRLIB_Start() merge into GRRLIB_Init(). * add GRRLIB_PtInRect, GRRLIB_RectInRect and GRRLIB_RectOnRect. - -* add GRRLIB_Exit to free the memory allocated by GRRLIB + +* GRRLIB_GetPixelFromtexImg and GRRLIB_SetPixelTotexImg ////////////////////////// BUGGED DO NOT USE !!! + +* add GRRLIB_Exit to free the memory allocated by GRRLIB have a look at the sample code to see how all this work ;) diff --git a/template/source/GRRLIB/GRRLIB.c b/template/source/GRRLIB/GRRLIB.c index 90f4396..8657101 100644 --- a/template/source/GRRLIB/GRRLIB.c +++ b/template/source/GRRLIB/GRRLIB.c @@ -432,6 +432,58 @@ bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2 GRRLIB_PtInRect(rect1x, rect1y, rect1w, rect1h, rect2x, rect2y+rect2h)); } +/** + * Return the color value of a pixel from a GRRLIB_texImg !!!!!!!!!!!!!!!! NOT WORKING NEED HELP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex){ + u8 *truc = (u8*)tex.data; + u32 x1,y1; + u8 r,g,b,a; + u32 value=0; + u32 offset; + + x1 = x >> 2; // div by 4 + y1 = y >> 2; // div by 4 + offset = (x1*64) + (x-(x1*4))*2+y*8; + + a=*(truc+offset); + r=*(truc+offset+1); + g=*(truc+offset+32); + b=*(truc+offset+33); + + value = (r<<24) | (g<<16) | (b<<8) | a; + + + return(value); +} + +/** + * Set the color value of a pixel to a GRRLIB_texImg !!!!!!!!!!!!!!!! NOT WORKING NEED HELP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color){ + u8 *truc = (u8*)tex.data; + u32 x1,y1; + u8 r,g,b,a; + u32 offset; + + x1 = x >> 2; // div by 4 + y1 = y >> 2; // div by 4 + offset = (x1*64) + (x-(x1*4))*2+y*8; + + a=color & 0xFF; + r=(color>>8) & 0xFF; + g=(color>>16) & 0xFF; + b=(color>>24) & 0xFF; + + + *(truc+offset)=a; + *(truc+offset+1)=r; + *(truc+offset+32)=g; + *(truc+offset+33)=b; + + +} + /** * * @param v diff --git a/template/source/GRRLIB/GRRLIB.h b/template/source/GRRLIB/GRRLIB.h index 1f3fc90..680b020 100644 --- a/template/source/GRRLIB/GRRLIB.h +++ b/template/source/GRRLIB/GRRLIB.h @@ -62,6 +62,9 @@ bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpad bool GRRLIB_RectInRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h); bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h); +u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex); +void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color); + void GRRLIB_GXEngine(Vector v[], u32 color, long count, u8 fmt); diff --git a/template/source/gfx/pixeltest.c b/template/source/gfx/pixeltest.c new file mode 100644 index 0000000..dae3af4 --- /dev/null +++ b/template/source/gfx/pixeltest.c @@ -0,0 +1,20 @@ +/* + This file was autogenerated by raw2c. +Visit http://www.devkitpro.org +*/ + +const unsigned char pixeltest[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0x08, 0x06, 0x00, 0x00, 0x00, 0x8c, 0xfe, 0xb8, + 0x6d, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, + 0x00, 0x06, 0x62, 0x4b, 0x47, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x43, 0xbb, 0x7f, + 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b, 0x13, + 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4d, 0x45, 0x07, 0xd9, 0x02, + 0x04, 0x14, 0x1e, 0x12, 0x30, 0x90, 0x66, 0x4b, 0x00, 0x00, 0x00, 0x37, 0x49, 0x44, 0x41, 0x54, + 0x58, 0xc3, 0xed, 0xce, 0x01, 0x0d, 0x00, 0x00, 0x08, 0x03, 0x20, 0xb5, 0x7f, 0xe7, 0x5b, 0x43, + 0x37, 0x48, 0x40, 0x27, 0x49, 0x1d, 0x36, 0x75, 0x9c, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, + 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xe0, + 0xd7, 0xe0, 0x02, 0x3e, 0xea, 0x04, 0x4c, 0xc6, 0x8c, 0xdb, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x49, + 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 +}; +const int pixeltest_size = sizeof(pixeltest); diff --git a/template/source/gfx/pixeltest.h b/template/source/gfx/pixeltest.h new file mode 100644 index 0000000..a1889f5 --- /dev/null +++ b/template/source/gfx/pixeltest.h @@ -0,0 +1,14 @@ +/* + This file was autogenerated by raw2c. +Visit http://www.devkitpro.org +*/ + +//--------------------------------------------------------------------------------- +#ifndef _pixeltest_h_ +#define _pixeltest_h_ +//--------------------------------------------------------------------------------- +extern const unsigned char pixeltest[]; +extern const int pixeltest_size; +//--------------------------------------------------------------------------------- +#endif //_pixeltest_h_ +//--------------------------------------------------------------------------------- diff --git a/template/source/gfx/pixeltest.png b/template/source/gfx/pixeltest.png new file mode 100644 index 0000000000000000000000000000000000000000..fa6cfde9dcb777d5ac8f979dde548d913d09cb99 GIT binary patch literal 183 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|*pj^6U4S$Y z{B+)352QE?JR*x37`TN&n2}-D90{Nxdx@v7EBj3*77;lig9&NgKp}Ha7srr@!*9@~ literal 0 HcmV?d00001 diff --git a/template/source/main.c b/template/source/main.c index a252ec0..f5c2663 100644 --- a/template/source/main.c +++ b/template/source/main.c @@ -20,6 +20,8 @@ #include "gfx/BMfont5.h" #include "gfx/test_jpg.h" #include "gfx/sprite.h" +#include "gfx/pixeltest.h" + // Tile stuff #define TILE_DELAY 10 @@ -55,6 +57,7 @@ Mtx GXmodelView2D; int main() { int left = 0, top = 0, page = 0, frame = TILE_DOWN + 1; unsigned int wait = TILE_DELAY, direction = TILE_DOWN, direction_new = TILE_DOWN; + int x=0,y=0,val=0; ir_t ir1; u32 wpaddown, wpadheld; Vector triangle[] = {{400,200,0.0f}, {500,400,0.0f}, {300,400,0.0f}}; @@ -67,6 +70,8 @@ int main() { GRRLIB_texImg tex_test_jpg = GRRLIB_LoadTextureJPG(test_jpg); + GRRLIB_texImg tex_pixeltest = GRRLIB_LoadTexturePNG(pixeltest); + GRRLIB_texImg tex_sprite_png = GRRLIB_LoadTexturePNG(sprite); GRRLIB_InitTileSet(&tex_sprite_png, 24, 32, 0); @@ -85,6 +90,8 @@ int main() { GRRLIB_texImg tex_BMfont5 = GRRLIB_LoadTexturePNG(BMfont5); GRRLIB_InitTileSet(&tex_BMfont5, 8, 16, 0); + + while(1) { WPAD_SetVRes(0, 640, 480); WPAD_ScanPads(); @@ -101,6 +108,16 @@ int main() { GRRLIB_Printf(5, 25, tex_BMfont2, GRRLIB_WHITE, 1, "IMAGES DEMO"); GRRLIB_DrawImg(10, 50, tex_test_jpg, 0, 1, 1, GRRLIB_WHITE); + GRRLIB_DrawImg(400, 150, tex_pixeltest, 0, 1, 1, GRRLIB_WHITE); + + for(y=0;y + for(x=0;x<(tex_pixeltest.w*20);x++){ + val = 1 + (int) (16777215.0 * (rand() / (RAND_MAX + 1.0))); + GRRLIB_SetPixelTotexImg(x,y,tex_pixeltest,(val<<8)|0xFF); + } + } //------------ + + // Draw a sprite GRRLIB_DrawTile(600, 400, tex_sprite_png, 0, 2, 2, GRRLIB_WHITE, 12*4); // Rupee GRRLIB_DrawTile(320+left, 240+top, tex_sprite_png, 0, 2, 2, GRRLIB_WHITE, frame);