rendered paste bodystruct VertexTexColor{ float u, v; /* Tex-coords. */ unsigned int color; float x, y, z; /* Coords. */};struct VertexNormalsColor{ unsigned int color; float n_x, n_y, n_z; /* Normals. */ float x, y, z; /* Coords. */};struct VertexTexColor __attribute__((aligned(16))) overlay_vertices[2] ={ {0.0, 0.0, 0xffff00ff, 0, 0, 1}, {1.0, 1.0, 0xffff00ff, 480, 272, 1},};int main(int argc, char* argv[]){ setupCallbacks(); TextureManager& texManager = TextureManager::instance(); int overlayId = texManager.loadTexture<PNGLoader>("overlay.png"); Texture *overlay = texManager.getTexture(overlayId); /* Recalc texture coords to make overlay cover whole screen. */ overlay_vertices[1].u = (float)overlay->width/overlay->textureWidth; overlay_vertices[1].v = (float)overlay->height/overlay->textureHeight; int heartVertices; VertexNormalsColor *heart = ObjLoader::load("heart.obj", &heartVertices); // setup GU void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888); void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888); void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444); sceGuInit(); sceGuStart(GU_DIRECT, list); sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH); sceGuDepthBuffer(zbp,BUF_WIDTH); sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2)); sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT); sceGuDepthRange(65535,0); sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); sceGuFrontFace(GU_CW); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_CULL_FACE); sceGuEnable(GU_TEXTURE_2D); sceGuEnable(GU_CLIP_PLANES); sceGuEnable(GU_BLEND); /* Enable lighting! */ sceGuEnable(GU_LIGHTING); sceGuEnable(GU_LIGHT0); /* Textures & blending*/ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexScale(1.0f,1.0f); sceGuTexOffset(0.0f,0.0f); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); int val = 0; while (running()) { sceGuStart(GU_DIRECT,list); // clear screen sceGuClearColor(0xffffff); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); /* Lights! */ { ScePspFVector3 lpos = { cosf(val * (GU_PI/180)) * 3.0f, 0, sinf(val * (GU_PI/180)) * 3.0f }; sceGuLight(0, GU_POINTLIGHT, GU_DIFFUSE_AND_SPECULAR, &lpos); sceGuLightColor(0, GU_DIFFUSE, 0xffff00ff); sceGuLightColor(0, GU_SPECULAR, 0xffffffff); sceGuLightAtt(0, 0.0f, 1.0f, 0.0f); sceGuSpecular(12.0f); sceGuAmbient(0x00222222); } // setup matrices for cube sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f); sceGumMatrixMode(GU_VIEW); sceGumLoadIdentity(); sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); { ScePspFVector3 pos = { 0, -0.75f, -2.5f }; ScePspFVector3 rot = { 0, val * 0.98f * (GU_PI/180.0f), 0}; ScePspFVector3 scale = { val * 0.01f, val * 0.98f, val * 0.01f }; sceGumTranslate(&pos); sceGumRotateXYZ(&rot); } /* XXX: THIS IS THE PROBLEMATIC SPOT. * With this piece of code as-is, I get a translucent object that doesn't have the * right color. (No matter if lighting is on or off) * * If I wrap this code in: * sceGuDisable(GU_TEXTURE_2D); <code> sceGuEnable(GU_TEXTURE_2D); * I get _nothing_ (just the white background & the overlay) if lighting is enabled, * and my object with the proper, uniform color if lighting is disabled. */ sceGuFrontFace(GU_CCW); sceGumDrawArray(GU_TRIANGLES, GU_COLOR_8888|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, heartVertices, 0, heart); sceGuFrontFace(GU_CW); /* XXX: END OF PROBLEMATIC SPOT. */ /* This below here renders an overlay that's mostly transparency, except for some blocks of color. * This works fine no matter what I do with the lighting. */ sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumOrtho(0, 480, 272, 0, -1, 1); sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); /* Setup & draw overlay texture. */ overlay->bind(); sceGumDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 2*3, 0, overlay_vertices); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); val++; } sceGuTerm(); sceKernelExitGame(); return 0;}