[NEW] GRRLIB_BMFX_Pixelate and lesson3 to show how to use it ;)

This commit is contained in:
N0NameN0 2009-02-15 00:41:32 +00:00
parent f457382f43
commit 56682fa5ff
8 changed files with 3096 additions and 4 deletions

View file

@ -556,6 +556,7 @@ void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc the texture source.
* @param texdest the texture destination. * @param texdest the texture destination.
* @param factor the blur factor.
*/ */
void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
int numba = (1+(factor<<1))*(1+(factor<<1)); int numba = (1+(factor<<1))*(1+(factor<<1));
@ -610,16 +611,41 @@ void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
* A texture effect. * A texture effect.
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc the texture source.
* @param texdest the texture grayscaled destination. * @param texdest the texture destination.
* @param factor The factor level of the effect.
*/
void GRRLIB_BMFX_Pixelate(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
unsigned int x, y;
unsigned int xx, yy;
u32 rgb;
for(x=0; x<texsrc.w-1-factor; x+= factor) {
for(y=0; y<texsrc.h-1-factor; y+=factor) {
rgb=GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for(xx=x; xx<x+factor; xx++) {
for(yy=y; yy<y+factor; yy++) {
GRRLIB_SetPixelTotexImg(xx, yy, texdest, rgb);
}
}
}
}
}
/**
* A texture effect.
* @see GRRLIB_FlushTex
* @param texsrc the texture source.
* @param texdest the texture destination.
* @param factor The factor level of the effect. * @param factor The factor level of the effect.
*/ */
void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
unsigned int x, y; unsigned int x, y;
int val1, val2, val3, val4; int val1, val2;
u32 val3, val4;
int factorx2 = factor*2; int factorx2 = factor*2;
for(y=0; y<texsrc.h; y++) { for(y=0; y<texsrc.h; y++) {
for(x=1; x<texsrc.w; x++) { for(x=0; x<texsrc.w; x++) {
val1 = x + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor; val1 = x + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;
val2 = y + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor; val2 = y + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;

View file

@ -71,6 +71,7 @@ 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_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_BMFX_Pixelate(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/lesson3/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_Pixelate 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_Pixelate(tex_pirate, tex_new1,1);
GRRLIB_FlushTex(tex_new1);
GRRLIB_BMFX_Pixelate(tex_pirate, tex_new2,2);
GRRLIB_FlushTex(tex_new2);
GRRLIB_BMFX_Pixelate(tex_pirate, tex_new3,3);
GRRLIB_FlushTex(tex_new3);
GRRLIB_BMFX_Pixelate(tex_pirate, tex_new4,4);
GRRLIB_FlushTex(tex_new4);
GRRLIB_BMFX_Pixelate(tex_pirate, tex_new5,5);
GRRLIB_FlushTex(tex_new5);
GRRLIB_BMFX_Pixelate(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;
}

View file

@ -56,7 +56,7 @@ ChangeLog :
* GRRLIB_CreateEmptyTexture and GRRLIB_FlushTex * GRRLIB_CreateEmptyTexture and GRRLIB_FlushTex
* New Bitmap FX: GRRLIB_BMFX_Grayscale, GRRLIB_BMFX_Invert and GRRLIB_BMFX_Scatter * New Bitmap FX: GRRLIB_BMFX_Grayscale, GRRLIB_BMFX_Invert, GRRLIB_BMFX_Scatter, GRRLIB_BMFX_Blur, GRRLIB_BMFX_Pixelate
* add GRRLIB_Exit to free the memory allocated by GRRLIB * add GRRLIB_Exit to free the memory allocated by GRRLIB