mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-12-23 02:39:19 +00:00
[NEW] GRRLIB_GetPixelFromtexImg and GRRLIB_SetPixelTotexImg !!!! BUGGED DO NOT USE until working ;) !!!
This commit is contained in:
parent
0bcea42377
commit
c0ababb4e4
7 changed files with 110 additions and 2 deletions
|
@ -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 ;)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
20
template/source/gfx/pixeltest.c
Normal file
20
template/source/gfx/pixeltest.c
Normal file
|
@ -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);
|
14
template/source/gfx/pixeltest.h
Normal file
14
template/source/gfx/pixeltest.h
Normal file
|
@ -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_
|
||||
//---------------------------------------------------------------------------------
|
BIN
template/source/gfx/pixeltest.png
Normal file
BIN
template/source/gfx/pixeltest.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 183 B |
|
@ -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<tex_pixeltest.h;y++){ //------------ <just a test>
|
||||
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);
|
||||
}
|
||||
} //------------ </just a test>
|
||||
|
||||
|
||||
// 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);
|
||||
|
|
Loading…
Reference in a new issue