Using PrimBuild
by Tony Richards · in Torque Game Engine Advanced · 08/09/2005 (8:55 pm) · 6 replies
Ok, pardon me for posting this if it's already been answered, but I've read the documentation, forums, searched the resources and haven't really found anything that shows a simple example of how to use PrimBuild. I thought I had it, but I'm doing something wrong.
I started with a simple code change to draw the mission area. I modified the mission area to match the spawn point of the camera so I'd know approximately where it would show up.
Then, in game.cpp/GameRenderWorld() I added made the following change.
Then I created the function GameRenderMissionArea() and added the appropriate includes at the top of the file.
I've tried using GFXTriangleStrip, I've tried drawPrimitive() vs drawPrimitives() but no luck. Some different variations have produced an odd looking shape and others have produced a cube of sorts.
I'm missing something, and maybe it's just because I bought TSE yesterday and I've only gotten a couple hours of sleep because I've been playing with it. :p New toys, ya know?
I started with a simple code change to draw the mission area. I modified the mission area to match the spawn point of the camera so I'd know approximately where it would show up.
Then, in game.cpp/GameRenderWorld() I added made the following change.
// Need to consoldate to one clear call // glClear(GL_DEPTH_BUFFER_BIT); GFX->setCullMode( GFXCullNone );//glDisable(GL_CULL_FACE); gClientSceneGraph->renderScene(); [b]GameRenderMissionArea();[/b] GFX->setZEnable( false ); //glDisable(GL_DEPTH_TEST); collisionTest.render();
Then I created the function GameRenderMissionArea() and added the appropriate includes at the top of the file.
void GameRenderMissionArea()
{
static RectI lastMissionArea;
static GFXVertexBuffer* pVertexBuffer = NULL;
static F32 height = 0.0;
static F32 depth = 0.0;
static U32 numPrims = 0;
// Initialize the last mission area so we have known values.
if (pVertexBuffer == NULL)
{
lastMissionArea.set(0, 0, 0, 0);
}
if (MissionArea::smMissionArea != lastMissionArea)
{
lastMissionArea = MissionArea::smMissionArea;
height = 300; // MissionArea::smflightCeiling;
depth = 50.0; // Override based on loweest terrain point?
if (pVertexBuffer)
{
// Is this the correct way to delete a vertext buffer?
delete pVertexBuffer;
pVertexBuffer = NULL;
}
// Create or re-create the primitive
PrimBuild::beginToBuffer(GFXTriangleList, 3);
// For now, lets just draw single solid triangle.
// When we draw more, switch to drawing GFXTriangleStrip
PrimBuild::color4f(1.0, 1.0, 1.0, 1.0);
// Side 1, Tri 1
PrimBuild::vertex3f(lastMissionArea.point.x, lastMissionArea.point.y, depth);
PrimBuild::vertex3f(lastMissionArea.point.x, lastMissionArea.point.y + lastMissionArea.extent.y, depth);
PrimBuild::vertex3f(lastMissionArea.point.x, lastMissionArea.point.y, height);
pVertexBuffer = PrimBuild::endToBuffer(numPrims);
}
if (pVertexBuffer)
{
// Render here.
//pVertexBuffer->prepare();
GFX->setVertexBuffer(pVertexBuffer);
//GFX->drawPrimitives();
GFX->drawPrimitive(GFXTriangleList, 0, numPrims);
}
// TODO: Fix this!
// ACK! pVertexBuffer is leaked, but only one per process.
// Would GFXBufferHandle<> or whatever help out?
}I've tried using GFXTriangleStrip, I've tried drawPrimitive() vs drawPrimitives() but no luck. Some different variations have produced an odd looking shape and others have produced a cube of sorts.
I'm missing something, and maybe it's just because I bought TSE yesterday and I've only gotten a couple hours of sleep because I've been playing with it. :p New toys, ya know?
About the author
I am the founder of IndieZen.org, a website dedicated to the Indie 2.0 Revolution where a number of Indie game development studios and individuals collaborate and share a suite of custom built open source game development tools and middleware.
#2
Ok, I took out all of the idiotic optimizing stuff and reverted to K.I.S.S, and it renders a white plane exactly where I expected it to render.
Now... next question... how do I apply a texture to it? I'm pretty sure I know how to apply UV mapping to it by using textCoord2f().
EDIT: Ok, that's a rhetorical question for now... :P I think I might have figured it out. Thanks for the nudge.
08/09/2005 (10:48 pm)
No. I think the transform is already set (left over from GameRenderWorld()) maybe?Ok, I took out all of the idiotic optimizing stuff and reverted to K.I.S.S, and it renders a white plane exactly where I expected it to render.
Now... next question... how do I apply a texture to it? I'm pretty sure I know how to apply UV mapping to it by using textCoord2f().
EDIT: Ok, that's a rhetorical question for now... :P I think I might have figured it out. Thanks for the nudge.
#3
08/11/2005 (9:24 am)
Ok, I fixed my problem by deriving MissionArea from a modified fxRenderObject instead of NetObject. That makes it show up correctly, reflect in the water, etc. The original way from the TGE resource I guess was a little hackish and when I copied it from the resource I didn't really know what I was doing (not to say I know what I'm doing now :P)
#4
08/15/2005 (10:57 am)
Glad you got it figured out. :)
#5
08/15/2005 (11:45 am)
You pointed me in the right direction... thanks for the help. Because of that simple question "Are you setting a material or a transform?" I blame you on my current lack of sleep... that got me to porting fxRenderObject, which let me understand a lot more than I'd ever understood about the rendering and mesh side of TSE/TGE, which led me down this neverending path... but the great thing is that I'm learning a whole lot about the insides of TSE. I've been coding non-stop with a few naps and food breaks since then. It just keeps rolling off my fingertips.
#6
08/15/2005 (6:38 pm)
Very cool. :)
Associate Kyle Carter