Welcome, Guest! Login | Register

Do-it-yourself-WireFrame! [Print this Article]
Posted by: Patrick
Date posted: Jun 30 2003
User Rating: 5 out of 5.0
Number of views: 5811
Number of comments: 2
Description: Rendering a wireframe of maps yourself
Hello folks. I've been wanting to do a second article/tutorial, and since this is incredibly easy, I figured it'd satisfy me for now. Please note that this tutorial will only work in OpenGL mode.

This tutorial will show you how to render a wireframe of Half-Life levels in-game yourself, using the TriangleAPI, and NOT loading the .BSP yourself.

Start by opening up the Client.dll workspace. Go in Tri.cpp, and make sure you have these #includes:
 CODE  

#include "hud.h"
#include "cl_util.h"
#include "const.h"
#include "com_model.h"
#include "studio.h"
#include "entity_state.h"
#include "cl_entity.h"
#include "dlight.h"
#include "triangleapi.h"
#include "r_studioint.h"
#include "StudioModelRenderer.h"
#include "GameStudioModelRenderer.h"


Now, right below those, you want to tell the compiler you're using a global called IEngineStudio. So, paste this:
 CODE  

extern engine_studio_api_t IEngineStudio;


Half-Life stores the map/bsp data in several data structures located in com_model.h (..\common\). The one we are particularly interested in is model_s.
engine_studio_api_t has a method called GetModelByIndex, which is what we need to get our model.

Now, somewhere above HUD_DrawNormalTriangles, add this function:
 CODE  

void RenderWireFrame (void)
{
    // all valid model_s' stored in the engine start at 1 by this method, not 0,
    // and the world model is always the first model.  Thus, it's at index 1.
    model_s *pModel = IEngineStudio.GetModelByIndex (1);

    // make sure it's a valid model_s pointer and the model type is mod_brush
    if ((pModel == NULL) || (pModel->type != mod_brush))
        return;

    // now it shouldn't crash if we do this
    // we're simply drawing every single edge in the world
    gEngfuncs.pTriAPI->Begin (TRI_LINES);
    gEngfuncs.pTriAPI->CullFace (TRI_NONE); // don't cull
    gEngfuncs.pTriAPI->RenderMode (kRenderNormal);  // normal render mode
    gEngfuncs.pTriAPI->Color4ub (255, 255, 255, 255);   // white lines

    // for all edges in the map
    for (int i = 0; i < pModel->numedges; i++)
    {
        // get the current edge at index i
        medge_t currentEdge = pModel->edges[i];
        // the medge_t's simply store indexes into a master vertex (mvertex_t) list,
        // so get those two vertexes
        mvertex_t currentVertexes[2] =
        {
            pModel->vertexes[currentEdge.v[0]],
            pModel->vertexes[currentEdge.v[1]]
        };

        // now render this edge/line
        gEngfuncs.pTriAPI->Vertex3fv (currentVertexes[0].position);
        gEngfuncs.pTriAPI->Vertex3fv (currentVertexes[1].position);
    }

    gEngfuncs.pTriAPI->End ();  // we're done rendering
}


All that's left is calling this function from within HUD_DrawNormalTriangles:
 CODE  

void DLLEXPORT HUD_DrawNormalTriangles( void )
{
    gHUD.m_Spectator.DrawOverview();
    RenderWireFrame ();
}


Done. Compile and test.

This tutorial is the first of a few I plan on doing involving the world triangle data. Perhaps I'll update it to only render visible edges, which is renderer API-dependent, so it's a little more complex.

Rate This Article
This article is currently rated: 5 out of 5.0 (2 Votes)

You have to register to rate this article.
User Comments Showing comments 1-2

Posted By: cct on Jan 23 2004 at 18:30:27
hm i thought world model is model 0

Posted By: InternetNightmare on May 26 2004 at 08:57:42
This tutorial works in DirectX mode as well :)


You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 05 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
knock knock
General | News
By: omega | Dec 22 2016
 
knock knock
General | News
By: MIFUNE | Oct 10 2015
 
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
 
knock knock
General | News
By: Whistler | Nov 05 2011
 
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
 
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Persuter | Aug 02 2009
 

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (9 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!