[CHG] GRRLIB_Screen2Texture should be used for composition, NoNameNo will make a demo soon

This commit is contained in:
Crayon2000 2009-11-25 21:25:17 +00:00
parent d747469c4d
commit f314c0521f
7 changed files with 0 additions and 306 deletions

View file

@ -336,66 +336,3 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) {
GRRLIB_FlushTex( my_texture ); GRRLIB_FlushTex( my_texture );
return my_texture; return my_texture;
} }
/**
* Compose a layer/sprite to a canvas/textured-image.
* Currently only performs "a-over-b (normal) alpha compositing" (opacity)
* Ie. Light source is behind the eye, not behind the canvas!
* @author BlueChip
* @param xoff The x-offset within the canvas (negative values allowed)
* @param yoff The y-offset within the canvas (negative values allowed)
* @param layer The layer/sprite to draw
* @param canvas The canvas/textured-image on which to draw
* @param mode Currently unused - will be composition mode
*/
void GRRLIB_Compose( int xoff, int yoff, GRRLIB_texImg* layer,
GRRLIB_texImg* canvas, GRRLIB_ComposeMode mode )
{
int x, y; // x & y on layer
int cnv_x, cnv_y; // x & y on canvas
float cnv_a, lyr_a, alpha; // Alpha of canvas & layer & result
u32 cnv_c, lyr_c; // Colour of pixel from canvas & layer
u32 new_r, new_g, new_b, new_a; // R, G, B & A values of result
// Loop through the layer, one pixel at a time
for (y = 0; y < layer->h; y++) {
cnv_y = y + yoff; // y coord of canvas pixel to edit
if (cnv_y < 0) continue ; // not on the canvas yet
if (cnv_y >= canvas->h) break; // off the bottom of the canvas
for (x = 0; x < layer->w; x++) {
cnv_x = x + xoff; // x coord of canvas pixel to edit
if (cnv_x < 0) continue ; // not on the canvas yet
if (cnv_x >= canvas->h) break; // off the right of the canvas
// Grab the working pixels from the canvas and layer
cnv_c = GRRLIB_GetPixelFromtexImg(cnv_x, cnv_y, canvas);
lyr_c = GRRLIB_GetPixelFromtexImg(x, y, layer);
// Calculate alpha value as 0.0 to 1.0 in 255th's
cnv_a = A(cnv_c) /255.0;
lyr_a = A(lyr_c) /255.0;
// Perform desired composition
switch (mode) {
default:
case GRRLIB_COMPOSE_NORMAL :
// Perform "a-over-b (normal) alpha compositing" (opacity)
// http://en.wikipedia.org/wiki/Alpha_compositing
new_a = (u32)( A(lyr_c) + (A(cnv_c) *(1.0 -lyr_a)) );
alpha = new_a /255.0;
new_r = ( (R(lyr_c) *lyr_a) + (R(cnv_c) *cnv_a *(1 -lyr_a)) ) /alpha;
new_g = ( (G(lyr_c) *lyr_a) + (G(cnv_c) *cnv_a *(1 -lyr_a)) ) /alpha;
new_b = ( (B(lyr_c) *lyr_a) + (B(cnv_c) *cnv_a *(1 -lyr_a)) ) /alpha;
break;
}
// Replace the old canvas pixel with the new one
GRRLIB_SetPixelTotexImg( cnv_x, cnv_y, canvas,
RGBA(new_r, new_g, new_b, new_a) );
}//for x
}// for y
GRRLIB_FlushTex(canvas);
}

View file

@ -65,14 +65,6 @@ typedef unsigned int uint;
//============================================================================== //==============================================================================
// typedefs, enumerators & structs // typedefs, enumerators & structs
//============================================================================== //==============================================================================
/**
* Compositions Modes.
*/
typedef enum Composition_Modes {
GRRLIB_COMPOSE_NORMAL, /**< NORMAL : a-over-b alpha composition (normal) */
} GRRLIB_ComposeMode;
//------------------------------------------------------------------------------
/** /**
* GRRLIB Blending Modes. * GRRLIB Blending Modes.
*/ */

View file

@ -125,8 +125,5 @@ GRRLIB_texImg* GRRLIB_LoadTexture (const u8 *my_img) ;
GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png) ; GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png) ;
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) ; GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) ;
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) ; GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) ;
void GRRLIB_Compose (int xoff, int yoff, GRRLIB_texImg* layer,
GRRLIB_texImg* canvas,
GRRLIB_ComposeMode mode) ;
#endif // __GRRLIB_FNLIB_H__ #endif // __GRRLIB_FNLIB_H__

View file

@ -1,76 +0,0 @@
# Quick'n'dirty makefile [BC] v2
ifeq ($(strip $(DEVKITPPC)),)
$(error "Use export DEVKITPPC=<path to>devkitPPC and try again")
endif
ifeq ($(strip $(DEVKITPRO)),)
$(error "Use export DEVKITPRO=<path to>devkitPRO and try again")
endif
APP := compose
ELF := $(APP).elf
DOL := $(APP).dol
MAP := $(notdir $(ELF)).map
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat
LIBS += -lwiiuse
#LIBS += -lmodplay -lasnd
LIBS += -lbte -logc
LIBS += -lm
BINDIR := $(DEVKITPPC)/bin
PREFIX := $(BINDIR)/powerpc-eabi-
CC := $(PREFIX)gcc
CXX := $(PREFIX)g++
AR := $(PREFIX)ar
AS := $(PREFIX)as
LD := $(CC)
OBJCOPY := $(PREFIX)objcopy
ELF2DOL := $(BINDIR)/elf2dol
UPLOAD := $(BINDIR)/wiiload
OGC := $(DEVKITPRO)/libogc
INCD := $(OGC)/include
LIBD := $(OGC)/lib/wii
MACHDEP := -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float
CFLAGS := -O2 -Wall $(MACHDEP) -I $(INCD)
LDFLAGS = $(MACHDEP) -Wl,-Map,$(MAP)
LIBPATHS := -L$(DEVKITPRO)/libogc/lib/wii
SRC := $(shell ls *.c)
SRCOBJ := $(patsubst %.c,%.o,$(SRC))
RES := $(shell ls *.png)
RESOBJ := $(patsubst %.png,%.o,$(RES))
RESC := $(patsubst %.png,%.c,$(RES))
RESH := $(patsubst %.png,%.h,$(RES))
OBJ := $(RESOBJ) $(SRCOBJ)
all : $(DOL)
$(DOL) : $(ELF)
@echo Converting to: $@
@$(ELF2DOL) $< $@
$(ELF) : $(OBJ)
@echo Linking as: $@
@$(CC) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@
clean :
rm -f $(OBJ) $(RESC) $(RESH) $(ELF) $(DOL) $(MAP)
run : $(DOL)
$(UPLOAD) $(DOL)
%.o : %.c
@echo Compiling: $<
@$(CC) $(CFLAGS) -c $< -o $@
.PRECIOUS : %.c
%.c : %.png
@echo Converting resource: $<
@$(BINDIR)/raw2c.exe $< 2>nul

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -1,156 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2009 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------
// Test Harness for alpha composition functions
// The composition function and this demo were both written by BlueChip
/*
PaintShopPro_X2 readings:
| | Blue-over-Red | Red-over-Blue |
|--------+---------------+---------------|
| Normal | 0x2D'00'D2'D8 | 0x96'00'69'D8 |
| | | |
*/
//------------------------------------------------------------------------------
#include <stdlib.h> // exit
#include <wiiuse/wpad.h>
#include <grrlib.h>
#include "red50.h"
#include "blue70.h"
//------------------------------------------------------------------------------
void wscan(ir_t* ir) ;
// Wiimote overscan (to allow the cursor to move off the dge of the screen)
#define WOVERX (200)
#define WOVERY (300)
#define WMU_MAX (2) // How many wiimotes to read
ir_t ir[WMU_MAX];
//------------------------------------------------------------------------------
void test_compose(void)
{
int redOnTop = 0; // Red square starts behind the blue one
// Our two translucent test images
GRRLIB_texImg* red = GRRLIB_LoadTexture(red50);
GRRLIB_texImg* blu = GRRLIB_LoadTexture(blue70);
// The canvas we will be composing on
GRRLIB_texImg* cnv = GRRLIB_CreateEmptyTexture(400,400);
// Loop until home key pressed
do {
// Scan the wiimotes
wscan(ir);
// 'A' toggles z-coord of red sqaure (on-top / behind)
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) redOnTop ^= 1 ;
// Clear canvas
GRRLIB_ClearTex(cnv);
// Compose canvas
if (!redOnTop)
GRRLIB_Compose(ir[0].x-180,ir[0].y-180, red, cnv, GRRLIB_COMPOSE_NORMAL);
GRRLIB_Compose(125,125, blu, cnv, GRRLIB_COMPOSE_NORMAL) ;
if ( redOnTop)
GRRLIB_Compose(ir[0].x-180,ir[0].y-180, red, cnv, GRRLIB_COMPOSE_NORMAL);
// Paint the screen black
GRRLIB_FillScreen(0x000000FF);
// Draw frame
GRRLIB_SetColorRGBA(0x808080FF);
GRRLIB_Rectangle(38,38,404,404,false);
GRRLIB_Rectangle(39,39,402,402,false);
// Draw Test bar
GRRLIB_SetColorRGBA(0xFFFFFFFF);
GRRLIB_Rectangle(283,50,20,380, true);
// Draw Composed Canvas
GRRLIB_DrawImg(40,40, cnv);
// Test card (alpha performed by Wii)
GRRLIB_Rectangle(570,50,20,450, true);
GRRLIB_DrawImg(450, 65, red);
GRRLIB_DrawImg(450,165, blu);
GRRLIB_DrawImg(450,265, red);
// Draw it [and workaround bug in GRRLIB]
GRRLIB_Render();
if (rmode->viTVMode &VI_NON_INTERLACE) VIDEO_WaitVSync() ;
} while(!(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)); // Exit on home key
// Free up the resources we are using to hold the canvas and layers
GRRLIB_FreeTexture(blu);
GRRLIB_FreeTexture(red);
GRRLIB_FreeTexture(cnv);
}
//------------------------------------------------------------------------------
void wscan(ir_t* ir)
{
int i;
WPAD_ScanPads();
for (i = 0; i < WMU_MAX; i++) {
WPAD_IR(i, &ir[i]);
ir->x -= WOVERX/2;
ir->y -= WOVERY/2;
}
}
//------------------------------------------------------------------------------
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
int i;
// Init graphics subsystem
GRRLIB_Init();
// Init the Wiimotes
WPAD_Init();
for (i = 0; i < WMU_MAX; i++) {
WPAD_SetVRes(i, rmode->fbWidth+WOVERX, rmode->xfbHeight+WOVERY);
WPAD_SetDataFormat(i, WPAD_FMT_BTNS_ACC_IR);
}
// Call the demo
test_compose();
// Clear up memory
GRRLIB_Exit();
exit(0);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB