mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 06:52:20 +00:00
[CHG] Pre-calculating stuff in GRRLIB_BMFX_Scatter
[CHG] Showing FPS on the template
This commit is contained in:
parent
b4b26eff31
commit
67ab9e9829
3 changed files with 40 additions and 21 deletions
|
@ -54,9 +54,9 @@ ChangeLog :
|
|||
|
||||
* GRRLIB_GetPixelFromtexImg and GRRLIB_SetPixelTotexImg
|
||||
|
||||
* GRRLIB_CreateEmptyTexture and GRRLIB_FlushTex
|
||||
|
||||
* New Bitmap FX: GRRLIB_BMFX_GrayScale
|
||||
* GRRLIB_CreateEmptyTexture and GRRLIB_FlushTex
|
||||
|
||||
* New Bitmap FX: GRRLIB_BMFX_GrayScale and GRRLIB_BMFX_Scatter
|
||||
|
||||
* add GRRLIB_Exit to free the memory allocated by GRRLIB
|
||||
|
||||
|
|
|
@ -515,17 +515,14 @@ void GRRLIB_FlushTex(GRRLIB_texImg tex)
|
|||
*/
|
||||
void GRRLIB_BMFX_GrayScale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
||||
unsigned int x, y;
|
||||
u8 r, g, b, gray;
|
||||
u8 gray;
|
||||
u32 color;
|
||||
|
||||
for(y=0; y<texsrc.h; y++) {
|
||||
for(x=0; x<texsrc.w; x++) {
|
||||
color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
|
||||
b = (color>>24) & 0xFF;
|
||||
g = (color>>16) & 0xFF;
|
||||
r = (color>>8) & 0xFF;
|
||||
gray = ((r*77 + g*150 + b*28) / (255));
|
||||
gray = ((((color>>8) & 0xFF)*77 + ((color>>16) & 0xFF)*150 + ((color>>24) & 0xFF)*28) / (255));
|
||||
|
||||
GRRLIB_SetPixelTotexImg(x, y, texdest,
|
||||
((gray << 24) | (gray << 16) | (gray << 8) | (color & 0xFF)));
|
||||
|
@ -542,20 +539,21 @@ void GRRLIB_BMFX_GrayScale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
|||
*/
|
||||
void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
|
||||
unsigned int x, y;
|
||||
int val1,val2,val3,val4;
|
||||
int val1, val2, val3, val4;
|
||||
int factorx2 = factor*2;
|
||||
|
||||
for(y=0;y<texsrc.h;y++){
|
||||
for(x=1;x<texsrc.w;x++){
|
||||
val1= 0 + (int) (factor*2 * (rand() / (RAND_MAX + 1.0))) - factor ;
|
||||
val2= 0 + (int) (factor*2 * (rand() / (RAND_MAX + 1.0))) - factor ;
|
||||
for(y=0; y<texsrc.h; y++) {
|
||||
for(x=1; x<texsrc.w; x++) {
|
||||
val1 = x + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;
|
||||
val2 = y + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;
|
||||
|
||||
if((x + val1 >= texsrc.w) && (x + val1 <0) && (y + val2 >= texsrc.h) && (y + val2 <0)){
|
||||
if((val1 >= texsrc.w) && (val1 <0) && (val2 >= texsrc.h) && (val2 <0)) {
|
||||
}
|
||||
else{
|
||||
val3=GRRLIB_GetPixelFromtexImg(x,y,texsrc);
|
||||
val4=GRRLIB_GetPixelFromtexImg(x+val1,y+val2,texsrc);
|
||||
else {
|
||||
val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
val4 = GRRLIB_GetPixelFromtexImg(val1, val2, texsrc);
|
||||
GRRLIB_SetPixelTotexImg(x, y, texdest, val4);
|
||||
GRRLIB_SetPixelTotexImg(x+val1, y+val2, texdest, val3);
|
||||
GRRLIB_SetPixelTotexImg(val1, val2, texdest, val3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
============================================*/
|
||||
#include "GRRLIB/GRRLIB.h"
|
||||
|
||||
#include <ogc/lwp_watchdog.h> // needed for gettime and ticks_to_millisecs
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wiiuse/wpad.h>
|
||||
#include <fat.h>
|
||||
|
||||
|
@ -51,10 +51,12 @@
|
|||
#define GRRLIB_WHITE 0xFFFFFFFF
|
||||
|
||||
Mtx GXmodelView2D;
|
||||
static u8 CalculateFrameRate();
|
||||
|
||||
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;
|
||||
u8 FPS = 0;
|
||||
|
||||
ir_t ir1;
|
||||
u32 wpaddown, wpadheld;
|
||||
|
@ -87,8 +89,6 @@ 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();
|
||||
|
@ -163,7 +163,9 @@ int main() {
|
|||
GRRLIB_Printf(left, top+350, tex_BMfont3, 0XFFFFFF50, 1, "TEXT WITH ALPHA");
|
||||
GRRLIB_Printf(left, top+400, tex_BMfont5, GRRLIB_LIME, 1, "This font has the 128 ASCII characters");
|
||||
}
|
||||
GRRLIB_Printf(500, 27, tex_BMfont5, GRRLIB_WHITE, 1, "Current FPS: %d", FPS);
|
||||
GRRLIB_Render();
|
||||
FPS = CalculateFrameRate();
|
||||
|
||||
if(wpaddown & WPAD_BUTTON_HOME) {
|
||||
exit(0);
|
||||
|
@ -221,3 +223,22 @@ int main() {
|
|||
free(tex_BMfont5.data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function calculates the number of frames we render each second.
|
||||
* @return The number of frames per second.
|
||||
*/
|
||||
static u8 CalculateFrameRate() {
|
||||
static u8 frameCount = 0;
|
||||
static u32 lastTime;
|
||||
static u8 FPS = 0;
|
||||
u32 currentTime = ticks_to_millisecs(gettime());
|
||||
|
||||
frameCount++;
|
||||
if(currentTime - lastTime > 1000) {
|
||||
lastTime = currentTime;
|
||||
FPS = frameCount;
|
||||
frameCount = 0;
|
||||
}
|
||||
return FPS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue