[NEW] GRRLIB_BMFX_Blur and lesson2 to show how to use it.

Take Care most BMFX are not provided to be used in real time, only to make precalc at code start ;)
This commit is contained in:
N0NameN0 2009-02-14 23:04:34 +00:00
parent 4349944ae7
commit f457382f43
7 changed files with 3121 additions and 0 deletions

View file

@ -551,6 +551,61 @@ void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
} }
} }
/**
* Blur a texture.
* @see GRRLIB_FlushTex
* @param texsrc the texture source.
* @param texdest the texture destination.
*/
void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
int numba = (1+(factor<<1))*(1+(factor<<1));
int x, y;
int k, l;
int tmp=0;
int newr, newg, newb, newa;
u32 colours[numba];
u32 thiscol;
for (x = 0; x < texsrc.w; x++) {
for (y = 0; y < texsrc.h; y++) {
newr = 0;
newg = 0;
newb = 0;
newa = 0;
tmp=0;
thiscol = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for (k = x - factor; k <= x + factor; k++) {
for (l = y - factor; l <= y + factor; l++) {
if (k < 0) { colours[tmp] = thiscol; }
else if (k >= texsrc.w) { colours[tmp] = thiscol; }
else if (l < 0) { colours[tmp] = thiscol; }
else if (l >= texsrc.h) { colours[tmp] = thiscol; }
else{ colours[tmp] = GRRLIB_GetPixelFromtexImg(k, l, texsrc); }
tmp++;
}
}
for (tmp = 0; tmp < numba; tmp++) {
newr += (colours[tmp] >> 24) & 0xFF;
newg += (colours[tmp] >> 16) & 0xFF;
newb += (colours[tmp] >> 8) & 0xFF;
newa += colours[tmp] & 0xFF;
}
newr /= numba;
newg /= numba;
newb /= numba;
newa /= numba;
GRRLIB_SetPixelTotexImg(x, y, texdest, (newr<<24) | (newg<<16) | (newb<<8) | newa);
}
}
}
/** /**
* A texture effect. * A texture effect.
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex

View file

@ -69,6 +69,7 @@ void GRRLIB_FlushTex(GRRLIB_texImg tex);
void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest); void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest);
void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest); void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest);
void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor);
void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor); void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor);
void GRRLIB_GXEngine(Vector v[], u32 color, long count, u8 fmt); void GRRLIB_GXEngine(Vector v[], u32 color, long count, u8 fmt);

140
examples/lesson2/Makefile Normal file
View file

@ -0,0 +1,140 @@
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC)
endif
include $(DEVKITPPC)/wii_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
GRRLIB := ../../GRRLIB
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source source/gfx $(GRRLIB)/GRRLIB $(GRRLIB)/lib/libpng/pngu
DATA := data
INCLUDES :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O2 -mrvl -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CURDIR)/$(GRRLIB)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
$(sFILES:.s=.o) $(SFILES:.S=.o)
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC)
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
#---------------------------------------------------------------------------------
run:
psoload $(TARGET).dol
#---------------------------------------------------------------------------------
reload:
psoload -r $(TARGET).dol
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)
#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o : %.jpg
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/
//---------------------------------------------------------------------------------
#ifndef _pirate_h_
#define _pirate_h_
//---------------------------------------------------------------------------------
extern const unsigned char pirate[];
extern const int pirate_size;
//---------------------------------------------------------------------------------
#endif //_pirate_h_
//---------------------------------------------------------------------------------

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View file

@ -0,0 +1,83 @@
/*===========================================
GRRLIB (GX version) 3.0.5 alpha
Code : NoNameNo
Additional Code : Crayon
GX hints : RedShade
How To use GRRLIB_BMFX_Blur example code
============================================*/
#include "../../../GRRLIB/GRRLIB/GRRLIB.h"
#include <stdlib.h>
#include <wiiuse/wpad.h>
#include "gfx/pirate.h"
Mtx GXmodelView2D;
int main() {
u32 wpaddown;
// Load the original texture and create 6 empty texture of the same size as the original one
GRRLIB_texImg tex_pirate = GRRLIB_LoadTexturePNG(pirate);
GRRLIB_texImg tex_new1 = GRRLIB_CreateEmptyTexture(tex_pirate.w, tex_pirate.h);
GRRLIB_texImg tex_new2 = GRRLIB_CreateEmptyTexture(tex_pirate.w, tex_pirate.h);
GRRLIB_texImg tex_new3 = GRRLIB_CreateEmptyTexture(tex_pirate.w, tex_pirate.h);
GRRLIB_texImg tex_new4 = GRRLIB_CreateEmptyTexture(tex_pirate.w, tex_pirate.h);
GRRLIB_texImg tex_new5 = GRRLIB_CreateEmptyTexture(tex_pirate.w, tex_pirate.h);
GRRLIB_texImg tex_new6 = GRRLIB_CreateEmptyTexture(tex_pirate.w, tex_pirate.h);
// Let's precalculte 6 differents blur texture with 6 differents blur factor
GRRLIB_BMFX_Blur(tex_pirate, tex_new1,1);
GRRLIB_FlushTex(tex_new1);
GRRLIB_BMFX_Blur(tex_pirate, tex_new2,2);
GRRLIB_FlushTex(tex_new2);
GRRLIB_BMFX_Blur(tex_pirate, tex_new3,3);
GRRLIB_FlushTex(tex_new3);
GRRLIB_BMFX_Blur(tex_pirate, tex_new4,4);
GRRLIB_FlushTex(tex_new4);
GRRLIB_BMFX_Blur(tex_pirate, tex_new5,5);
GRRLIB_FlushTex(tex_new5);
GRRLIB_BMFX_Blur(tex_pirate, tex_new6,6);
GRRLIB_FlushTex(tex_new6);
GRRLIB_Init();
WPAD_Init();
while(1) {
WPAD_ScanPads();
wpaddown = WPAD_ButtonsDown(0);
GRRLIB_FillScreen(0xFFFFFFFF);
GRRLIB_DrawImg(10, 50, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_DrawImg(10+tex_pirate.w*1, 50, tex_new1, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_DrawImg(10+tex_pirate.w*2, 50, tex_new2, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_DrawImg(10+tex_pirate.w*3, 50, tex_new3, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_DrawImg(10, 50+tex_pirate.h*1, tex_new4, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_DrawImg(10+tex_pirate.w*1, 50+tex_pirate.h*1, tex_new5, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_DrawImg(10+tex_pirate.w*2, 50+tex_pirate.h*1, tex_new6, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_Render();
if(wpaddown & WPAD_BUTTON_HOME) {
exit(0);
}
}
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
free(tex_pirate.data);
free(tex_new1.data);
free(tex_new2.data);
free(tex_new3.data);
free(tex_new4.data);
free(tex_new5.data);
free(tex_new6.data);
return 0;
}