mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 15:02:20 +00:00
[ADD] GRRLIB_CompoStart and GRRLIB_CompoEnd for Real GX compositing
[ADD] Compositing Sample Code [CHG] Ported nonameno03 sample code to new the setting variable fashion
This commit is contained in:
parent
4a4a931797
commit
a3024c20b7
11 changed files with 1439 additions and 20 deletions
|
@ -160,6 +160,8 @@ int GRRLIB_Init (void) {
|
|||
// Initialise the filing system
|
||||
if (!fatInitDefault()) error_code = -2;
|
||||
|
||||
TrashTex = memalign(32, rmode->fbWidth * rmode->efbHeight * 4);
|
||||
|
||||
VIDEO_SetBlack(false); // Enable video output
|
||||
return error_code;
|
||||
}
|
||||
|
@ -188,6 +190,8 @@ void GRRLIB_Exit (void) {
|
|||
GX_DrawDone();
|
||||
GX_AbortFrame();
|
||||
|
||||
// free the temp Texture (allocated for compositing)
|
||||
free(TrashTex);
|
||||
// Free up memory allocated for frame buffers & FIFOs
|
||||
if (xfb[0] != NULL) { free(MEM_K1_TO_K0(xfb[0])); xfb[0] = NULL; }
|
||||
if (xfb[1] != NULL) { free(MEM_K1_TO_K0(xfb[1])); xfb[1] = NULL; }
|
||||
|
|
|
@ -23,7 +23,7 @@ THE SOFTWARE.
|
|||
#include <grrlib.h>
|
||||
|
||||
/**
|
||||
* Make a snapshot of the screen in a texture.
|
||||
* Make a snapshot of the screen in a texture WITHOUT ALPHA LAYER.
|
||||
* @param posx top left corner of the grabbed part.
|
||||
* @param posy top left corner of the grabbed part.
|
||||
* @param tex A pointer to a texture representing the screen or NULL if an error occurs.
|
||||
|
@ -38,3 +38,32 @@ void GRRLIB_Screen2Texture (int posx, int posy, GRRLIB_texImg *tex, bool clear)
|
|||
GRRLIB_FlushTex(tex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start GX Compositing Process.
|
||||
*/
|
||||
void GRRLIB_CompoStart (void){
|
||||
GX_SetPixelFmt(GX_PF_RGBA6_Z24,GX_ZC_LINEAR);
|
||||
GX_PokeAlphaRead(GX_READ_NONE);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* End GX Compositing Process (Make a snapshot of the screen in a texture WITH ALPHA LAYER).
|
||||
* @param posx top left corner of the grabbed part.
|
||||
* @param posy top left corner of the grabbed part.
|
||||
* @param tex A pointer to a texture representing the screen or NULL if an error occurs.
|
||||
* @info EFB is cleared after this function.
|
||||
*/
|
||||
void GRRLIB_CompoEnd(int posx, int posy, GRRLIB_texImg *tex){
|
||||
GRRLIB_Screen2Texture(posx, posy, tex, FALSE);
|
||||
|
||||
GX_SetTexCopySrc(0, 0, rmode->fbWidth, rmode->efbHeight);
|
||||
GX_SetTexCopyDst(rmode->fbWidth, rmode->efbHeight, GX_TF_RGBA8, GX_FALSE);
|
||||
GX_CopyTex(TrashTex, GX_TRUE);
|
||||
GX_PixModeSync();
|
||||
|
||||
if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR) ;
|
||||
else GX_SetPixelFmt(GX_PF_RGB8_Z24 , GX_ZC_LINEAR) ;
|
||||
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ typedef struct tagRGBQUAD {
|
|||
GRR_EXTERN GXRModeObj *rmode;
|
||||
GRR_EXTERN void *xfb[2] GRR_INITS(NULL, NULL);
|
||||
GRR_EXTERN u32 fb GRR_INIT(0);
|
||||
|
||||
GRR_EXTERN void *TrashTex;
|
||||
//==============================================================================
|
||||
// procedure and function prototypes
|
||||
// Inline function handling - http://www.greenend.org.uk/rjk/2003/03/inline.html
|
||||
|
@ -273,4 +273,4 @@ GRR_EXTERN u32 fb GRR_INIT(0);
|
|||
* This example shows the minimum code required to use GRRLIB.
|
||||
* It could be used as a template to start a new project.
|
||||
* More elaborate examples can be found inside the \e examples folder.
|
||||
*/
|
||||
*/
|
||||
|
|
|
@ -117,7 +117,8 @@ void GRRLIB_Render (void) ;
|
|||
//------------------------------------------------------------------------------
|
||||
// GRRLIB_snapshot.c - Create a texture containing a snapshot of a part of the framebuffer
|
||||
void GRRLIB_Screen2Texture (int posx, int posy, GRRLIB_texImg *tex, bool clear) ;
|
||||
|
||||
void GRRLIB_CompoStart (void);
|
||||
void GRRLIB_CompoEnd(int posx, int posy, GRRLIB_texImg *tex);
|
||||
//------------------------------------------------------------------------------
|
||||
// GRRLIB_texEdit.c - Modifying the content of a texture
|
||||
|
||||
|
|
139
examples/compositing/Makefile
Normal file
139
examples/compositing/Makefile
Normal file
|
@ -0,0 +1,139 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
# 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
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source source/gfx
|
||||
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 := -lgrrlib -lpngu -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
|
||||
#---------------------------------------------------------------------------------
|
1164
examples/compositing/source/gfx/font3d.c
Normal file
1164
examples/compositing/source/gfx/font3d.c
Normal file
File diff suppressed because it is too large
Load diff
14
examples/compositing/source/gfx/font3d.h
Normal file
14
examples/compositing/source/gfx/font3d.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
This file was autogenerated by raw2c.
|
||||
Visit http://www.devkitpro.org
|
||||
*/
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
#ifndef _font3d_h_
|
||||
#define _font3d_h_
|
||||
//---------------------------------------------------------------------------------
|
||||
extern const unsigned char font3d[];
|
||||
extern const int font3d_size;
|
||||
//---------------------------------------------------------------------------------
|
||||
#endif //_font3d_h_
|
||||
//---------------------------------------------------------------------------------
|
BIN
examples/compositing/source/gfx/font3d.png
Normal file
BIN
examples/compositing/source/gfx/font3d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
65
examples/compositing/source/main.c
Normal file
65
examples/compositing/source/main.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*===========================================
|
||||
NoNameNo Compositing Sample Code
|
||||
Bugged since Screen2texture conversion
|
||||
loose color precision.
|
||||
============================================*/
|
||||
#include <grrlib.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <malloc.h>
|
||||
#include <wiiuse/wpad.h>
|
||||
|
||||
#include "gfx/font3d.h"
|
||||
extern GXRModeObj *rmode;
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
float rot=0;
|
||||
float i=0;
|
||||
int circsize=150;
|
||||
|
||||
GRRLIB_Init();
|
||||
WPAD_Init();
|
||||
|
||||
|
||||
GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(font3d);
|
||||
GRRLIB_InitTileSet(tex_font, 64, 64, 32);
|
||||
GRRLIB_SetHandle (tex_font, tex_font->tilew/2, tex_font->tileh+circsize);
|
||||
|
||||
GRRLIB_texImg *tex_screen;
|
||||
tex_screen = GRRLIB_CreateEmptyTexture(rmode->fbWidth,rmode->efbHeight);
|
||||
|
||||
GRRLIB_Settings.antialias = true;
|
||||
|
||||
while(1) {
|
||||
WPAD_ScanPads();
|
||||
if(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0);
|
||||
|
||||
GRRLIB_CompoStart ();
|
||||
GRRLIB_SetAlpha(0xff);
|
||||
for(i=0;i<360;i+=30){
|
||||
GRRLIB_Settings.rotation= i+rot;
|
||||
GRRLIB_DrawTile((rmode->fbWidth/2)-(tex_font->tilew/2), (rmode->efbHeight/2)-(tex_font->tileh+circsize),tex_font,65-32+((int)i/45));
|
||||
}
|
||||
GRRLIB_CompoEnd(0, 0, tex_screen);
|
||||
|
||||
GRRLIB_Settings.rotation=0;
|
||||
rot-=0.6;
|
||||
|
||||
|
||||
GRRLIB_SetAlpha(0xff);
|
||||
GRRLIB_DrawImg(50, 50,tex_screen);
|
||||
GRRLIB_SetAlpha(0xFF);
|
||||
GRRLIB_DrawImg(100, 100,tex_screen);
|
||||
|
||||
GRRLIB_Render();
|
||||
}
|
||||
|
||||
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
|
||||
GRRLIB_FreeTexture(tex_screen);
|
||||
GRRLIB_FreeTexture(tex_font);
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -62,16 +62,17 @@ void GRRLIB_addon_Button(int indice, int x,int y,u32 col, int wpadx, int wpady,
|
|||
bg[2].x = x+4+1*16;
|
||||
}
|
||||
|
||||
GRRLIB_DrawTile(x, y, tex_GRRLIBbutton , 0, 1, 1, col,0 );
|
||||
GRRLIB_DrawTileQuad(bg, tex_GRRLIBbutton, col,1 );
|
||||
GRRLIB_DrawTile(bg[1].x, y, tex_GRRLIBbutton , 0, 1, 1, col,2);
|
||||
GRRLIB_SetColorRGBA(col);
|
||||
GRRLIB_DrawTile(x, y, tex_GRRLIBbutton, 0 );
|
||||
GRRLIB_DrawTileQuad(bg, tex_GRRLIBbutton, 1 );
|
||||
GRRLIB_DrawTile(bg[1].x, y, tex_GRRLIBbutton , 2);
|
||||
|
||||
if(GRRLIB_PtInRect(x, y, butwidth, 24, wpadx, wpady)) {
|
||||
if((toto[0]=='^') && (toto[1]=='U')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFFFF, 1, "%c", 0xa1);
|
||||
else if((toto[0]=='^') && (toto[1]=='D')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFFFF, 1, "%c", 0xa2);
|
||||
else if((toto[0]=='^') && (toto[1]=='L')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFFFF, 1, "%c", 0xa3);
|
||||
else if((toto[0]=='^') && (toto[1]=='R')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFFFF, 1, "%c", 0xa4);
|
||||
else GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFFFF, 1, toto);
|
||||
if((toto[0]=='^') && (toto[1]=='U')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa1);
|
||||
else if((toto[0]=='^') && (toto[1]=='D')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa2);
|
||||
else if((toto[0]=='^') && (toto[1]=='L')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa3);
|
||||
else if((toto[0]=='^') && (toto[1]=='R')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa4);
|
||||
else GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, toto);
|
||||
if(WPADDown & but) {
|
||||
*resdown=indice;
|
||||
}
|
||||
|
@ -80,10 +81,12 @@ void GRRLIB_addon_Button(int indice, int x,int y,u32 col, int wpadx, int wpady,
|
|||
}
|
||||
}
|
||||
else {
|
||||
if((toto[0]=='^') && (toto[1]=='U')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFF77, 1, "%c", 0xa1);
|
||||
else if((toto[0]=='^') && (toto[1]=='D')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFF77, 1, "%c", 0xa2);
|
||||
else if((toto[0]=='^') && (toto[1]=='L')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFF77, 1, "%c", 0xa3);
|
||||
else if((toto[0]=='^') && (toto[1]=='R')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFF77, 1, "%c", 0xa4);
|
||||
else GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, 0xFFFFFF77, 1, toto);
|
||||
GRRLIB_SetColorRGBA(0xFFFFFF77);
|
||||
if((toto[0]=='^') && (toto[1]=='U')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa1);
|
||||
else if((toto[0]=='^') && (toto[1]=='D')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa2);
|
||||
else if((toto[0]=='^') && (toto[1]=='L')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa3);
|
||||
else if((toto[0]=='^') && (toto[1]=='R')) GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, "%c", 0xa4);
|
||||
else GRRLIB_Printf(x+4, y+2, tex_GRRLIBfont, toto);
|
||||
GRRLIB_SetColorRGBA(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ int main() {
|
|||
GRRLIB_addon_Button(3, 100,180,0x00FFFFFF, wpadx, wpady, WPADDown, WPADHeld, WPAD_BUTTON_A, &resdown, &resheld, " My Third Button ");
|
||||
GRRLIB_addon_Button(4, 100,260,0xCCCCCCFF, wpadx, wpady, WPADDown, WPADHeld, WPAD_BUTTON_A, &resdown, &resheld, " -- QuIt -- ");
|
||||
|
||||
GRRLIB_Printf(100, 310, tex_GRRLIBfont, 0xFFFFFFFF, 1, "button down : %d",resdown);
|
||||
GRRLIB_Printf(100, 330, tex_GRRLIBfont, 0xFFFFFFFF, 1, "button held : %d",resheld);
|
||||
GRRLIB_Printf(100, 310, tex_GRRLIBfont, "button down : %d",resdown);
|
||||
GRRLIB_Printf(100, 330, tex_GRRLIBfont, "button held : %d",resheld);
|
||||
|
||||
if(resdown==4){
|
||||
exit(0);
|
||||
|
@ -53,7 +53,7 @@ int main() {
|
|||
|
||||
resdown=0,resheld=0;
|
||||
|
||||
GRRLIB_DrawImg(wpadx-32, wpady-32, tex_pointer , 0, 1, 1, 0xFFFFFFFF );
|
||||
GRRLIB_DrawImg(wpadx-32, wpady-32, tex_pointer);
|
||||
|
||||
GRRLIB_Render();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue