|
How can I draw textured and flat/gouraud shaded primitives in the same frame? April 04, 2014 04:16PM | Registered: 12 years ago Posts: 45 |
#include stdio.h
#include stdlib.h
#include string.h
#include malloc.h
#include math.h
#include gccore.h
#include wiiuse/wpad.h
// My test texture (any 128x256 texture should do)
#include "sampletex_tpl.h"
#include "sampletex.h"
#define DEFAULT_FIFO_SIZE (256*1024)
GXRModeObj *rmode = NULL;
void *gp_fifo = NULL;
GXColor ClearColor = {0, 0, 0, 0xff};
Mtx myView, myModel, myModelView;
Mtx44 myPersp;
void *myFB[2] = { NULL, NULL};
int ActiveFB = 0;
TPLFile sampleTPL;
GXTexObj texture;
// Function prototypes
int main();
void init();
int main() {
// Initialize everything
init();
while(1) {
WPAD_ScanPads();
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0);
// Prepare for rendering
GX_SetViewport(0, 0, rmode->fbWidth, rmode->efbHeight, 0, 1);
// Set appropriate texturing modes
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
// 'Bind' to our texture
GX_LoadTexObj(&texture, GX_TEXMAP0);
// Set geometry stuff
guMtxIdentity(myModelView);
guMtxTransApply (myModelView, myModelView, 0.0F, 0.0F, 0.0F);
GX_LoadPosMtxImm(myModelView, GX_PNMTX0);
// Draw the texture
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
// Top-left
GX_Position2f32(0, 0);
GX_Color3f32(1.0f, 1.0f, 1.0f);
GX_TexCoord2f32(0, 0);
// Top-right
GX_Position2f32(256, 0);
GX_Color3f32(1.0f, 1.0f, 1.0f);
GX_TexCoord2f32(1, 0);
// Bottom-right
GX_Position2f32(256, 512);
GX_Color3f32(1.0f, 1.0f, 1.0f);
GX_TexCoord2f32(1, 1);
// Bottom-left
GX_Position2f32(0, 512);
GX_Color3f32(1.0f, 1.0f, 1.0f);
GX_TexCoord2f32(0, 1);
GX_End();
/*
// Draw a plain quad
GX_Begin(GX_QUADS, GX_VTXFMT1, 4);
// Top-left
GX_Position2f32(300, 40);
GX_Color3f32(1.0f, 1.0f, 1.0f);
// Top-right
GX_Position2f32(500, 40);
GX_Color3f32(1.0f, 1.0f, 1.0f);
// Bottom-right
GX_Position2f32(500, 80);
GX_Color3f32(1.0f, 1.0f, 1.0f);
// Bottom-left
GX_Position2f32(300, 80);
GX_Color3f32(1.0f, 1.0f, 1.0f);
GX_End();
*/
// Display the rendered scene
ActiveFB ^= 1;
GX_SetZMode(GX_FALSE, GX_LEQUAL, GX_FALSE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(myFB[ActiveFB], GX_TRUE);
GX_DrawDone();
VIDEO_SetNextFramebuffer(myFB[ActiveFB]);
VIDEO_Flush();
VIDEO_WaitVSync();
}
return(0);
}
void init() {
int aspect=0;
int xfbHeight=0;
float yscale=0;
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9) {
aspect = 1;
} else {
aspect = 0;
}
// Setup video
VIDEO_Init();
// Allocate memory blocks as our framebuffers (two for double buffering)
rmode = VIDEO_GetPreferredMode(NULL);
myFB[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
myFB[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// To fully get rid of the border on widescreen TVs
if (aspect) {
rmode->viWidth += 58;
if (rmode->viWidth > 720) rmode->viWidth = 720;
}
// More video init stuff
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(myFB[ActiveFB]);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
// Setup fifo and the 'flipper'
gp_fifo = memalign(32, DEFAULT_FIFO_SIZE);
memset(gp_fifo, 0, DEFAULT_FIFO_SIZE);
// Initialize the GX system
GX_Init(gp_fifo, DEFAULT_FIFO_SIZE);
// Clears the bg to color and z buffer
GX_SetCopyClear(ClearColor, 0x00ffffff);
// More GX setup stuff
GX_SetViewport(0, 0, rmode->fbWidth, rmode->efbHeight, 0, 1);
yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
xfbHeight = GX_SetDispCopyYScale(yscale);
GX_SetScissor(0, 0, rmode->fbWidth, rmode->efbHeight);
GX_SetDispCopySrc(0, 0, rmode->fbWidth, rmode->efbHeight);
GX_SetDispCopyDst(rmode->fbWidth, xfbHeight);
GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter);
GX_SetFieldMode(rmode->field_rendering, ((rmode->viHeight == 2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE));
if (rmode->aa)
GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
else
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
GX_SetCullMode(GX_CULL_NONE);
GX_CopyDisp(myFB[ActiveFB], GX_TRUE);
GX_SetDispCopyGamma(GX_GM_1_0);
GX_ClearVtxDesc();
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0);
GX_SetNumChans(1);
GX_SetNumTexGens(1);
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
GX_InvVtxCache();
GX_InvalidateTexAll();
// Upload our texture
TPL_OpenTPLFromMemory(&sampleTPL, (void*)sampletex_tpl, sampletex_tpl_size);
TPL_GetTexture(&sampleTPL, sampletex, &texture);
// Setup orthogonal projection matrix
if (aspect) { // Anamorphic widescreen
guOrtho(myPersp, 0, rmode->viHeight - 1, 0, (rmode->viWidth - 1) + 140, 0, 10);
} else { // Normal
guOrtho(myPersp, 0, rmode->viHeight - 1, 0, rmode->viWidth - 1, 0, 10);
}
GX_LoadProjectionMtx(myPersp, GX_ORTHOGRAPHIC);
WPAD_Init();
}|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 04, 2014 08:22PM | Moderator Registered: 16 years ago Posts: 686 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 05, 2014 03:03AM | Registered: 12 years ago Posts: 45 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 05, 2014 10:13AM | Moderator Registered: 16 years ago Posts: 686 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 07, 2014 04:15PM | Registered: 15 years ago Posts: 58 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 07, 2014 08:05PM | Moderator Registered: 16 years ago Posts: 686 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 08, 2014 10:08AM | Registered: 15 years ago Posts: 58 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 08, 2014 12:05PM | Moderator Registered: 16 years ago Posts: 686 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 08, 2014 12:41PM | Registered: 15 years ago Posts: 58 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 08, 2014 01:27PM | Moderator Registered: 16 years ago Posts: 686 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 08, 2014 01:39PM | Registered: 15 years ago Posts: 58 |
|
Re: How can I draw textured and flat/gouraud shaded primitives in the same frame? April 08, 2014 05:32PM | Moderator Registered: 16 years ago Posts: 686 |