mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 23:12:21 +00:00
[ADD] First Diffuse Light functions (lot of work need about light in general...)
[ADD] a Diffuse Light sample code (3 lights sources)
This commit is contained in:
parent
5344e1db1b
commit
dd1aa7045f
8 changed files with 28503 additions and 13 deletions
|
@ -76,9 +76,11 @@ void GRRLIB_Camera3dSettings(f32 posx, f32 posy, f32 posz,
|
||||||
* @param minDist Minimal distance for the cam.
|
* @param minDist Minimal distance for the cam.
|
||||||
* @param maxDist Maximal distance for the cam.
|
* @param maxDist Maximal distance for the cam.
|
||||||
* @param fov Field of view for the cam.
|
* @param fov Field of view for the cam.
|
||||||
|
* @param colormode False, GX won't need vertex colors , True, GX will need vertex colors.
|
||||||
* @param texturemode False, GX won't need texture coordinate, True, GX will need texture coordinate.
|
* @param texturemode False, GX won't need texture coordinate, True, GX will need texture coordinate.
|
||||||
|
* @param normalmode False, GX won't need normal coordinate, True, GX will need normal coordinate.
|
||||||
*/
|
*/
|
||||||
void GRRLIB_3dMode(f32 minDist, f32 maxDist, f32 fov, bool texturemode) {
|
void GRRLIB_3dMode(f32 minDist, f32 maxDist, f32 fov, bool colormode, bool texturemode, bool normalmode) {
|
||||||
Mtx m;
|
Mtx m;
|
||||||
|
|
||||||
guLookAt(_GRR_view, &_GRR_cam, &_GRR_up, &_GRR_look);
|
guLookAt(_GRR_view, &_GRR_cam, &_GRR_up, &_GRR_look);
|
||||||
|
@ -90,17 +92,18 @@ void GRRLIB_3dMode(f32 minDist, f32 maxDist, f32 fov, bool texturemode) {
|
||||||
|
|
||||||
GX_ClearVtxDesc();
|
GX_ClearVtxDesc();
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
if(normalmode==TRUE) GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT);
|
||||||
|
if(colormode==TRUE) GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
|
||||||
if(texturemode==FALSE) GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
if(texturemode==TRUE) GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
||||||
else GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
|
||||||
|
|
||||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
|
||||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
if(normalmode==TRUE) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
|
||||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
if(colormode==TRUE) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
||||||
|
if(texturemode==TRUE ) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||||
|
|
||||||
if(texturemode==FALSE) GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
if(texturemode==FALSE) GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
else GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
|
else GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,18 +142,25 @@ void GRRLIB_2dMode() {
|
||||||
* @param angx x rotation angle of the object.
|
* @param angx x rotation angle of the object.
|
||||||
* @param angy y rotation angle of the object.
|
* @param angy y rotation angle of the object.
|
||||||
* @param angz z rotation angle of the object.
|
* @param angz z rotation angle of the object.
|
||||||
|
* @param scalx x scale of the object.
|
||||||
|
* @param scaly y scale of the object.
|
||||||
|
* @param scalz z scale of the object.
|
||||||
*/
|
*/
|
||||||
void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz) {
|
void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) {
|
||||||
Mtx m, mv, rx, ry, rz;
|
Mtx m, m1, mv, rx, ry, rz;
|
||||||
Mtx mvi ;
|
Mtx mvi ;
|
||||||
|
|
||||||
guMtxIdentity(m);
|
guMtxIdentity(m1);
|
||||||
|
guMtxScaleApply(m1, m1, scalx, scaly, scalz);
|
||||||
|
|
||||||
guMtxRotAxisDeg(rx, &_GRRaxisx, angx);
|
guMtxRotAxisDeg(rx, &_GRRaxisx, angx);
|
||||||
guMtxRotAxisDeg(ry, &_GRRaxisy, angy);
|
guMtxRotAxisDeg(ry, &_GRRaxisy, angy);
|
||||||
guMtxRotAxisDeg(rz, &_GRRaxisz, angz);
|
guMtxRotAxisDeg(rz, &_GRRaxisz, angz);
|
||||||
guMtxConcat(ry, rx, m);
|
guMtxConcat(ry, rx, m);
|
||||||
guMtxConcat(m, rz, m);
|
guMtxConcat(m, rz, m);
|
||||||
|
|
||||||
|
guMtxConcat(m, m1, m);
|
||||||
|
|
||||||
guMtxTransApply(m, m, posx, posy, posz);
|
guMtxTransApply(m, m, posx, posy, posz);
|
||||||
guMtxConcat(_GRR_view, m, mv);
|
guMtxConcat(_GRR_view, m, mv);
|
||||||
GX_LoadPosMtxImm(mv, GX_PNMTX0);
|
GX_LoadPosMtxImm(mv, GX_PNMTX0);
|
||||||
|
@ -160,6 +170,7 @@ void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 ang
|
||||||
GX_LoadNrmMtxImm(mv, GX_PNMTX0);
|
GX_LoadNrmMtxImm(mv, GX_PNMTX0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the texture to an object (contributed by chris_c aka DaShAmAn).
|
* Set the texture to an object (contributed by chris_c aka DaShAmAn).
|
||||||
* @param tex poiter to an image texture (GRRLIB_texImg format).
|
* @param tex poiter to an image texture (GRRLIB_texImg format).
|
||||||
|
@ -186,3 +197,46 @@ void GRRLIB_SetTexture(GRRLIB_texImg *tex, bool rep) {
|
||||||
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
|
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise a Diffuse Light.
|
||||||
|
* @param id a light ID in libogc style : GX_LIGHT0,..., GX_LIGHT7).
|
||||||
|
* @param lpos a guVector x,y,z position of the light.
|
||||||
|
* @param lcol color of the light.
|
||||||
|
*/
|
||||||
|
void GRRLIB_InitLight(u8 id, guVector lpos, u32 lcol){
|
||||||
|
GXLightObj MyLight;
|
||||||
|
guVecMultiply(_GRR_view, &lpos, &lpos);
|
||||||
|
GX_InitLightPos(&MyLight, lpos.x, lpos.y, lpos.z);
|
||||||
|
GX_InitLightColor(&MyLight, (GXColor) { R(lcol), G(lcol),B(lcol), A(lcol) });
|
||||||
|
GX_InitLightAttn(&MyLight, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F);
|
||||||
|
GX_LoadLightObj(&MyLight, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All Light Off, colors come from the Vertex.
|
||||||
|
*/
|
||||||
|
void GRRLIB_LightOff(void){
|
||||||
|
GX_SetNumChans(1);
|
||||||
|
GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX, 0, GX_DF_NONE, GX_AF_NONE);
|
||||||
|
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define what light to turn on and some other param.
|
||||||
|
* @param id light IDs of the desired switched ON lights (ORed) (ie GX_LIGHT0|GX_LIGHT7).
|
||||||
|
* @param ambcol Ambiant color u32 formated
|
||||||
|
* @param matcol Material color u32 formated.
|
||||||
|
* @param colsrc Material color sources comes from the Vertex ???? (True/False)
|
||||||
|
*/
|
||||||
|
void GRRLIB_LightSwitch(u8 id, u32 ambcol, u32 matcol, u8 colsrc){
|
||||||
|
u8 src;
|
||||||
|
if(colsrc==0) src = GX_SRC_REG;
|
||||||
|
else src = GX_SRC_VTX;
|
||||||
|
|
||||||
|
GX_SetNumChans(1);
|
||||||
|
GX_SetChanCtrl(GX_COLOR0A0, GX_ENABLE, GX_SRC_REG, src, id, GX_DF_CLAMP,GX_AF_SPOT);
|
||||||
|
GX_SetChanAmbColor(GX_COLOR0A0, (GXColor) { R(ambcol), G(ambcol), B(ambcol), A(ambcol)});
|
||||||
|
GX_SetChanMatColor(GX_COLOR0A0, (GXColor) { R(matcol), G(matcol), B(matcol), A(matcol)});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,10 +143,13 @@ void GRRLIB_GeckoPrintf (const char *text, ...);
|
||||||
// GRRLIB_3D.c - 3D functions for GRRLIB
|
// GRRLIB_3D.c - 3D functions for GRRLIB
|
||||||
void GRRLIB_SetBackgroundColour(u8 r, u8 g, u8 b, u8 a);
|
void GRRLIB_SetBackgroundColour(u8 r, u8 g, u8 b, u8 a);
|
||||||
void GRRLIB_Camera3dSettings(f32 posx, f32 posy, f32 posz, f32 upx, f32 upy, f32 upz, f32 lookx, f32 looky, f32 lookz);
|
void GRRLIB_Camera3dSettings(f32 posx, f32 posy, f32 posz, f32 upx, f32 upy, f32 upz, f32 lookx, f32 looky, f32 lookz);
|
||||||
void GRRLIB_3dMode(f32 minDist, f32 maxDist, f32 fov, bool texturemode);
|
void GRRLIB_3dMode(f32 minDist, f32 maxDist, f32 fov, bool colormode, bool texturemode, bool normalmode);
|
||||||
void GRRLIB_2dMode();
|
void GRRLIB_2dMode();
|
||||||
void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz);
|
void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz);
|
||||||
void GRRLIB_SetTexture(GRRLIB_texImg *tex, bool rep);
|
void GRRLIB_SetTexture(GRRLIB_texImg *tex, bool rep);
|
||||||
|
void GRRLIB_InitLight(u8 id, guVector lpos, u32 lcol);
|
||||||
|
void GRRLIB_LightOff(void);
|
||||||
|
void GRRLIB_LightSwitch(u8 id, u32 ambcol, u32 matcol, u8 colsrc);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// GRRLIB_Freetype.c - FreeType function for GRRLIB
|
// GRRLIB_Freetype.c - FreeType function for GRRLIB
|
||||||
|
|
139
examples/3D_LightDiffuse/Makefile
Normal file
139
examples/3D_LightDiffuse/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 -lfreetype -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
|
||||||
|
#---------------------------------------------------------------------------------
|
67
examples/3D_LightDiffuse/source/gfx/font.c
Normal file
67
examples/3D_LightDiffuse/source/gfx/font.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
This file was autogenerated by raw2c.
|
||||||
|
Visit http://www.devkitpro.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
const unsigned char font[] = {
|
||||||
|
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||||
|
0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x30, 0x08, 0x06, 0x00, 0x00, 0x00, 0x60, 0xc5, 0xa3,
|
||||||
|
0xdf, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
|
||||||
|
0x03, 0x5e, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0x9d, 0xd1, 0xb2, 0xad, 0x20, 0x08, 0x40,
|
||||||
|
0x4f, 0x4d, 0xff, 0xff, 0xcb, 0xdd, 0xa7, 0x3d, 0xd3, 0x6d, 0x6c, 0x54, 0x40, 0x40, 0x5d, 0xeb,
|
||||||
|
0xe9, 0xcc, 0xd9, 0x91, 0x26, 0x48, 0x44, 0x4a, 0xc7, 0xdf, 0x20, 0xee, 0xfb, 0xbe, 0x7f, 0x7f,
|
||||||
|
0x1f, 0xc7, 0x71, 0xfc, 0x81, 0x2b, 0xcf, 0xf1, 0xd7, 0xea, 0xe0, 0x7d, 0xae, 0xf7, 0x39, 0x6b,
|
||||||
|
0xbf, 0x43, 0x4e, 0xbb, 0x78, 0xea, 0xe7, 0x4b, 0x87, 0x5f, 0xd4, 0x74, 0xdb, 0x3b, 0xff, 0xb5,
|
||||||
|
0xed, 0xb7, 0xca, 0xbf, 0xe5, 0x0e, 0xef, 0x81, 0x86, 0x78, 0x63, 0x1f, 0x7d, 0x0e, 0x74, 0x3f,
|
||||||
|
0xaf, 0xf3, 0xfb, 0xd2, 0x57, 0xc9, 0xc1, 0xb4, 0x1e, 0x6b, 0xe9, 0x2c, 0x4b, 0xc7, 0xf6, 0xf6,
|
||||||
|
0xff, 0x79, 0xcc, 0x89, 0x59, 0xc0, 0xca, 0x13, 0xbe, 0x37, 0xb2, 0xe0, 0x66, 0xa8, 0x8b, 0xce,
|
||||||
|
0x66, 0x1b, 0xef, 0x0b, 0xd3, 0xc0, 0xe0, 0x01, 0x5b, 0x68, 0x95, 0xad, 0x39, 0xb8, 0x5a, 0x5a,
|
||||||
|
0x64, 0x44, 0xaa, 0x44, 0x23, 0x8f, 0x03, 0x5c, 0x14, 0x9c, 0x1e, 0x58, 0x3b, 0x3f, 0xaf, 0x7e,
|
||||||
|
0x5a, 0xd8, 0x77, 0xeb, 0xf9, 0x2e, 0x2f, 0x25, 0x30, 0x21, 0xc1, 0x7b, 0xc2, 0x7b, 0x4e, 0x64,
|
||||||
|
0xeb, 0x09, 0xbc, 0xab, 0xf3, 0xb3, 0x6a, 0xab, 0xf5, 0x25, 0xc9, 0x19, 0x69, 0x98, 0x00, 0xb0,
|
||||||
|
0xb7, 0xf3, 0x8b, 0x86, 0x47, 0x60, 0x18, 0x1a, 0xc9, 0x7b, 0x47, 0xff, 0xa5, 0xb7, 0x9b, 0x1e,
|
||||||
|
0xed, 0x67, 0x72, 0x14, 0xd9, 0x9c, 0x5f, 0x8f, 0x0d, 0x78, 0xd8, 0xcb, 0xb3, 0x8d, 0x6b, 0x07,
|
||||||
|
0x83, 0x80, 0xbd, 0x9c, 0xe0, 0x88, 0x27, 0x96, 0x59, 0xfa, 0x6f, 0xe5, 0xc0, 0xac, 0xaf, 0x37,
|
||||||
|
0xab, 0x13, 0x24, 0x02, 0x04, 0xf8, 0x70, 0x00, 0xd1, 0x69, 0x9b, 0xde, 0x08, 0x76, 0x87, 0x47,
|
||||||
|
0x57, 0xe9, 0x3a, 0x40, 0xf7, 0x47, 0xe0, 0x9e, 0x85, 0x93, 0x00, 0x3c, 0x85, 0xe4, 0x88, 0xfc,
|
||||||
|
0xb6, 0xb3, 0x11, 0x1c, 0x20, 0x48, 0x74, 0xf9, 0x75, 0x07, 0x5e, 0xc5, 0x11, 0xcd, 0xe4, 0x50,
|
||||||
|
0xac, 0x77, 0xfc, 0x58, 0xdc, 0x5c, 0x34, 0x3b, 0x47, 0x24, 0x7d, 0xc8, 0xf8, 0x16, 0x1e, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x51, 0x97, 0x93, 0x79, 0xff, 0xd6, 0xd5,
|
||||||
|
0xb8, 0x51, 0x12, 0x33, 0x43, 0x12, 0x55, 0x5a, 0x8f, 0x0c, 0xf4, 0x48, 0xf4, 0x3f, 0x62, 0x9d,
|
||||||
|
0x9b, 0xa7, 0xfd, 0x6a, 0xe7, 0x60, 0xa6, 0xf6, 0x23, 0xe5, 0xcd, 0x1d, 0xe0, 0xa8, 0x7a, 0x5e,
|
||||||
|
0xb3, 0xcb, 0xb3, 0x4c, 0xc1, 0xc7, 0x01, 0x5a, 0x17, 0xea, 0xf4, 0x68, 0x1f, 0xf9, 0x38, 0x79,
|
||||||
|
0xea, 0x01, 0x02, 0xc0, 0xb6, 0xb8, 0xef, 0x04, 0x19, 0x51, 0xfb, 0x6b, 0xf5, 0x55, 0xef, 0x33,
|
||||||
|
0x5c, 0x5f, 0xe4, 0x3a, 0x2c, 0x22, 0xea, 0x79, 0xc6, 0x2a, 0xb2, 0xf6, 0x5f, 0x49, 0xfe, 0xfa,
|
||||||
|
0xfd, 0xf3, 0x67, 0xc0, 0xda, 0xed, 0x3f, 0xda, 0x5c, 0x98, 0x54, 0x5e, 0x33, 0x01, 0x25, 0xd7,
|
||||||
|
0xaf, 0x95, 0x87, 0x75, 0x1c, 0xb0, 0xa6, 0x1f, 0xd6, 0xf2, 0x59, 0xf5, 0x20, 0xd9, 0xce, 0xa7,
|
||||||
|
0xd1, 0x57, 0xcb, 0x38, 0xfe, 0xb7, 0x17, 0x58, 0x53, 0x60, 0xb0, 0xa7, 0x73, 0x4f, 0x47, 0x21,
|
||||||
|
0x89, 0xe6, 0x4a, 0xf2, 0xda, 0xbc, 0x8e, 0x24, 0x87, 0xf0, 0xee, 0xbf, 0x55, 0x81, 0xc6, 0x59,
|
||||||
|
0x23, 0x9b, 0xc8, 0xbe, 0x66, 0xca, 0xaf, 0x6a, 0xed, 0xa0, 0x55, 0x3e, 0xab, 0x6d, 0x44, 0x47,
|
||||||
|
0x78, 0xbd, 0x01, 0x16, 0x39, 0x40, 0x80, 0x0d, 0x22, 0x5e, 0x28, 0x73, 0x66, 0x1b, 0xfc, 0xe8,
|
||||||
|
0x47, 0x08, 0x0f, 0xc3, 0x6a, 0x6d, 0x63, 0xa6, 0x8f, 0xfa, 0xdc, 0x9d, 0xe0, 0x98, 0x90, 0xcf,
|
||||||
|
0x20, 0x7f, 0x66, 0x74, 0x14, 0x38, 0x41, 0xe8, 0x7d, 0xdc, 0xf9, 0x81, 0x13, 0x44, 0xbe, 0x47,
|
||||||
|
0xfe, 0xb2, 0x56, 0xf8, 0x8e, 0x6f, 0xe4, 0x46, 0x5d, 0x3f, 0x39, 0x40, 0xec, 0x6f, 0xb5, 0xb1,
|
||||||
|
0xca, 0xa6, 0x2b, 0x72, 0x80, 0x00, 0xb0, 0xef, 0xd3, 0x83, 0x26, 0xac, 0x8c, 0xd8, 0x4a, 0xd6,
|
||||||
|
0xda, 0xf6, 0xc8, 0x8f, 0x3f, 0x5b, 0xf7, 0x1f, 0xd6, 0x89, 0x6a, 0x6a, 0xfd, 0xa8, 0xed, 0x64,
|
||||||
|
0xc8, 0x32, 0x7f, 0x76, 0x9b, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0,
|
||||||
|
0x26, 0x26, 0xe5, 0x68, 0x34, 0xc7, 0xb5, 0x92, 0xa5, 0x1c, 0x57, 0xed, 0x9c, 0xcd, 0x03, 0xbf,
|
||||||
|
0x69, 0x3d, 0xb8, 0xd2, 0xf8, 0xce, 0x78, 0xfd, 0x52, 0xfb, 0xf1, 0x2c, 0x07, 0x55, 0xda, 0x36,
|
||||||
|
0x97, 0xb1, 0x1c, 0x9c, 0x45, 0x3d, 0x4f, 0x29, 0x7c, 0x17, 0xd8, 0xfa, 0x8e, 0x22, 0xdc, 0x4b,
|
||||||
|
0xac, 0x91, 0xb7, 0xd8, 0xcb, 0x3c, 0xba, 0xfd, 0x5a, 0xbb, 0x91, 0xd7, 0x5f, 0x73, 0xca, 0xbc,
|
||||||
|
0x31, 0xcc, 0x37, 0x7f, 0xac, 0x60, 0x1d, 0x20, 0x00, 0x6c, 0x0b, 0x11, 0x20, 0x10, 0x61, 0xc0,
|
||||||
|
0xb6, 0x3a, 0xb9, 0x46, 0x87, 0x98, 0xde, 0x64, 0xfb, 0x36, 0xc7, 0x4c, 0x45, 0x4d, 0x33, 0x8c,
|
||||||
|
0x9f, 0x34, 0x1f, 0xa8, 0xa9, 0xe7, 0x88, 0x03, 0x8a, 0xaf, 0x87, 0x19, 0xb5, 0x90, 0xf9, 0x8a,
|
||||||
|
0x7e, 0x06, 0x8f, 0xca, 0x21, 0xd4, 0x72, 0x51, 0xdc, 0x8d, 0x73, 0xeb, 0xef, 0x7d, 0x5c, 0x6f,
|
||||||
|
0xc1, 0x4d, 0xf4, 0x5f, 0x9e, 0xd3, 0x11, 0xf5, 0x30, 0x23, 0xf3, 0xad, 0xe4, 0x00, 0x61, 0xe9,
|
||||||
|
0x48, 0x1f, 0xa0, 0xcb, 0x01, 0x8e, 0x30, 0x2c, 0xeb, 0x73, 0xb6, 0xde, 0x4d, 0x22, 0xfa, 0x8a,
|
||||||
|
0xfc, 0x7a, 0x25, 0xe1, 0x7b, 0xfa, 0x94, 0x69, 0xfc, 0x24, 0x25, 0xc2, 0xa2, 0x4b, 0xc1, 0x79,
|
||||||
|
0xeb, 0xff, 0xf4, 0xea, 0x04, 0x4e, 0x10, 0x79, 0x9c, 0x20, 0xe3, 0x9f, 0xcd, 0x09, 0x5e, 0xd9,
|
||||||
|
0x8c, 0x2b, 0x7b, 0x5e, 0x86, 0xf5, 0x61, 0xe8, 0xc4, 0x9a, 0xe7, 0x4b, 0x84, 0x19, 0xaf, 0xd3,
|
||||||
|
0xb3, 0x5f, 0xd6, 0x6d, 0xb1, 0x0c, 0x06, 0xdc, 0x26, 0x39, 0xa3, 0x20, 0x77, 0x82, 0xdc, 0x78,
|
||||||
|
0x17, 0x8e, 0x00, 0xa3, 0x97, 0x31, 0x94, 0x8c, 0x4f, 0xfb, 0xf5, 0xae, 0xe8, 0xc9, 0xe3, 0xd9,
|
||||||
|
0x7f, 0x49, 0xfb, 0x96, 0x7d, 0x58, 0xc5, 0x7e, 0x5a, 0xae, 0xa3, 0x26, 0x17, 0xad, 0x7f, 0xab,
|
||||||
|
0xf1, 0xe7, 0x25, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0xf0, 0x0f,
|
||||||
|
0xab, 0xb9, 0x5f, 0xb5, 0x2f, 0x5e, 0xd2, 0x50, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
|
||||||
|
0xae, 0x42, 0x60, 0x82
|
||||||
|
};
|
||||||
|
const int font_size = sizeof(font);
|
14
examples/3D_LightDiffuse/source/gfx/font.h
Normal file
14
examples/3D_LightDiffuse/source/gfx/font.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
This file was autogenerated by raw2c.
|
||||||
|
Visit http://www.devkitpro.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
#ifndef _font_h_
|
||||||
|
#define _font_h_
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
extern const unsigned char font[];
|
||||||
|
extern const int font_size;
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
#endif //_font_h_
|
||||||
|
//---------------------------------------------------------------------------------
|
BIN
examples/3D_LightDiffuse/source/gfx/font.png
Normal file
BIN
examples/3D_LightDiffuse/source/gfx/font.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 932 B |
110
examples/3D_LightDiffuse/source/main.c
Normal file
110
examples/3D_LightDiffuse/source/main.c
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/*===========================================
|
||||||
|
NoNameNo
|
||||||
|
Simple Diffuse Light Sample Code
|
||||||
|
With 3 Light sources.
|
||||||
|
|
||||||
|
Note : This torus hardcoded obj will be removed
|
||||||
|
when we will have nice primitive functions.
|
||||||
|
============================================*/
|
||||||
|
#include <grrlib.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <wiiuse/wpad.h>
|
||||||
|
|
||||||
|
#include "gfx/font.h"
|
||||||
|
|
||||||
|
extern Mtx _GRR_view;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct GRRLIB_3dObj {
|
||||||
|
int NbFace;
|
||||||
|
guVector *Pos;
|
||||||
|
guVector *Tex;
|
||||||
|
guVector *Nrm;
|
||||||
|
int *FacPos;
|
||||||
|
int *FacTex;
|
||||||
|
int *FacNrm;
|
||||||
|
} GRRLIB_3dObj;
|
||||||
|
|
||||||
|
#include "torus.h"
|
||||||
|
|
||||||
|
|
||||||
|
void GRRLIB_Draw3dObj(GRRLIB_3dObj obj, u32 col, bool tex, bool norm){
|
||||||
|
int i;
|
||||||
|
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, obj.NbFace*3);
|
||||||
|
for(i=0;i<obj.NbFace*3;i+=3){
|
||||||
|
GX_Position3f32(obj.Pos[obj.FacPos[i]-1].x,obj.Pos[obj.FacPos[i]-1].y,-obj.Pos[obj.FacPos[i]-1].z);
|
||||||
|
if(col) GX_Color1u32 (col);
|
||||||
|
if(norm) GX_Normal3f32(obj.Nrm[obj.FacNrm[i]-1].x,obj.Nrm[obj.FacNrm[i]-1].y,-obj.Nrm[obj.FacNrm[i]-1].z);
|
||||||
|
if(tex) GX_TexCoord2f32(obj.Tex[obj.FacTex[i]-1].x, obj.Tex[obj.FacTex[i]-1].y);
|
||||||
|
|
||||||
|
GX_Position3f32(obj.Pos[obj.FacPos[i+1]-1].x,obj.Pos[obj.FacPos[i+1]-1].y,-obj.Pos[obj.FacPos[i+1]-1].z);
|
||||||
|
if(col) GX_Color1u32 (col);
|
||||||
|
if(norm) GX_Normal3f32(obj.Nrm[obj.FacNrm[i+1]-1].x,obj.Nrm[obj.FacNrm[i+1]-1].y,-obj.Nrm[obj.FacNrm[i+1]-1].z);
|
||||||
|
if(tex) GX_TexCoord2f32(obj.Tex[obj.FacTex[i+1]-1].x, obj.Tex[obj.FacTex[i+1]-1].y);
|
||||||
|
|
||||||
|
GX_Position3f32(obj.Pos[obj.FacPos[i+2]-1].x,obj.Pos[obj.FacPos[i+2]-1].y,-obj.Pos[obj.FacPos[i+2]-1].z);
|
||||||
|
if(col) GX_Color1u32 (col);
|
||||||
|
if(norm) GX_Normal3f32(obj.Nrm[obj.FacNrm[i+2]-1].x,obj.Nrm[obj.FacNrm[i+2]-1].y,-obj.Nrm[obj.FacNrm[i+2]-1].z);
|
||||||
|
if(tex) GX_TexCoord2f32(obj.Tex[obj.FacTex[i+2]-1].x, obj.Tex[obj.FacTex[i+2]-1].y);
|
||||||
|
}
|
||||||
|
GX_End();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
float a=0;
|
||||||
|
u8 Amb=0x80;
|
||||||
|
f32 zlight=0.0f;
|
||||||
|
|
||||||
|
GRRLIB_Init();
|
||||||
|
WPAD_Init();
|
||||||
|
|
||||||
|
Obj3dInittorus();
|
||||||
|
|
||||||
|
GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(font);
|
||||||
|
GRRLIB_InitTileSet(tex_font, 16, 16, 32);
|
||||||
|
|
||||||
|
GRRLIB_Settings.antialias = true;
|
||||||
|
|
||||||
|
GRRLIB_SetBackgroundColour(0x00, 0x00, 0x00, 0xFF);
|
||||||
|
GRRLIB_Camera3dSettings(0.0f,0.0f,13.0f, 0,1,0, 0,0,0);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
GRRLIB_2dMode();
|
||||||
|
WPAD_ScanPads();
|
||||||
|
if(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0);
|
||||||
|
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_PLUS){if(Amb<255) Amb++; }
|
||||||
|
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_MINUS){if(Amb>0) Amb--; }
|
||||||
|
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A){zlight++; }
|
||||||
|
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_B){zlight--; }
|
||||||
|
|
||||||
|
|
||||||
|
GRRLIB_3dMode(0.1,1000,45,0,0,1);
|
||||||
|
GRRLIB_ObjectView(0,0,0, a,a*2,a*3, 3,3,3);
|
||||||
|
|
||||||
|
GRRLIB_InitLight(GX_LIGHT0, (guVector){-6, 0, zlight}, 0xFF0000FF);
|
||||||
|
GRRLIB_InitLight(GX_LIGHT1, (guVector){ 6, 0, zlight}, 0x00FF00FF);
|
||||||
|
GRRLIB_InitLight(GX_LIGHT2, (guVector){ 0,-6, zlight}, 0x0000FFFF);
|
||||||
|
|
||||||
|
GRRLIB_LightSwitch(GX_LIGHT0|GX_LIGHT1|GX_LIGHT2,RGBA(Amb,Amb,Amb,0xFF),0x808080FF,0);
|
||||||
|
|
||||||
|
GRRLIB_Draw3dObj(torus,0,0,1);
|
||||||
|
|
||||||
|
a+=0.5f;
|
||||||
|
|
||||||
|
GRRLIB_LightOff();
|
||||||
|
// Switch To 2D Mode to display text
|
||||||
|
GRRLIB_2dMode();
|
||||||
|
GRRLIB_Printf((640-(16*35))/2, 20, tex_font, 0xFFFFFFFF, 1, "(PLUS / MINUS) AMBIENT = 0X%02X%02X%02XFF",Amb,Amb,Amb,Amb);
|
||||||
|
GRRLIB_Printf((640-(16*35))/2, 36, tex_font, 0xFFFFFFFF, 1, " (A / B) ZLIGHT = %f ",zlight);
|
||||||
|
|
||||||
|
GRRLIB_Render();
|
||||||
|
}
|
||||||
|
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
|
||||||
|
GRRLIB_FreeTexture(tex_font);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
28103
examples/3D_LightDiffuse/source/torus.h
Normal file
28103
examples/3D_LightDiffuse/source/torus.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue