Welcome, Guest! Login | Register

Orthogonal Drawing with TriAPI [Print this Article]
Posted by: omega
Date posted: Apr 13 2003
User Rating: N/A
Number of views: 2945
Number of comments: 1
Description:

NOTES:
* X-Out's breakout tutorial used this shell as a base.
* This ONLY works in OpenGL and Direct3D modes.



I decided to whip up this tutorial to show you the simplicity of drawing triangles in orthogonal mode using TriAPI. This is really simple, and I'm even doing all the work for you! An example regarding how to draw a quad over the entire screen is included at the end of the article.

Step #1: Load up tri.cpp and add this shell at the very bottom:

 CODE  

/*
=================
HUD_DrawOrthoTriangles
Orthogonal Triangles -- (relative to resolution,
smackdab on the screen) add them here
=================
*/

void HUD_DrawOrthoTriangles( void )
{
}

Step #2: Open up HUD_Redraw.cpp
Prototype the function above redraw()

 CODE  

void HUD_DrawOrthoTriangles( void );
int CHud :: Redraw( float flTime, int intermission )
{


Step #3: Add the function inside redraw, so it's called:

HUD_DrawOrthoTriangles is called from the HUD draw functions, because at this point the engine is already in orthogonal mode. Hence, the Z coord is a "magic 0", because it's not rendering in world space in ortho, it's 2D.
 CODE  


    ...
    pList = pList->pNext;
  }
    }

    
    //omega;draw orthogonal triangles

    HUD_DrawOrthoTriangles();


    // are we in demo mode? do we need to draw the logo in the top corner?

    if (m_iLogo)
    ...



Step #4: Make use of it!

Example:
 CODE  

#define ORTHOEXAMPLE
#ifdef ORTHOEXAMPLE

void OrthoExample()
{
     gEngfuncs.pTriAPI->RenderMode(kRenderTransAdd);
//additive

     // use hotglow, or any other sprite for the texture

     gEngfuncs.pTriAPI->SpriteTexture( (struct model_s *)
     gEngfuncs.GetSpritePointer(SPR_Load("sprites/hotglow.spr")), 0);

     gEngfuncs.pTriAPI->CullFace( TRI_NONE );
//no culling
     gEngfuncs.pTriAPI->Begin(TRI_QUADS);
//start our quad

     //remember, always list vertices in counter-clockwise
     // order, unless you want the quad to be backwards =)
     // the third value of vertex3f will always be 0 in ortho mode,
     // don't change it unless you wan't funny things to happen.

     //top left

     gEngfuncs.pTriAPI->TexCoord2f(0.0f, 1.0f);
     gEngfuncs.pTriAPI->Vertex3f(0, 0, 0);


     //bottom left
     gEngfuncs.pTriAPI->TexCoord2f(0.0f, 0.0f);
     gEngfuncs.pTriAPI->Vertex3f(0, ScreenHeight, 0);


     //bottom right
     gEngfuncs.pTriAPI->TexCoord2f(1.0f, 0.0f);
     gEngfuncs.pTriAPI->Vertex3f(ScreenWidth, ScreenHeight, 0);


     //top right
     gEngfuncs.pTriAPI->TexCoord2f(1.0f, 1.0f);
     gEngfuncs.pTriAPI->Vertex3f(ScreenWidth, 0, 0);

     gEngfuncs.pTriAPI->End();
//end our list of vertexes
     gEngfuncs.pTriAPI->RenderMode(kRenderNormal); //return to normal
}
#endif
void HUD_DrawOrthoTriangles( void )
{
#ifdef ORTHOEXAMPLE
     OrthoExample();
#endif
}


That about does it for this "tutorial". You now have the framework to draw triangles onto the hud with ease using TriAPI. Have fun, and enjoy! If you have any questions, email me at omega@thewavelength.net.

-omega

Rate This Article
This article has not yet been rated.

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

Posted By: Unbreakable on Oct 07 2006 at 12:33:29
Is all your tutorials like this!? You don't tell us where to put anything.

Open up HUD_Redraw.cpp
Prototype the function above redraw()....????

I want to learn how to use TriApi, but this explains nothing. When doing a tutorial, you have to look at it from the other end, from the learners perspective.

I'm just a beginner so I am trying to learn this, but I can't work with any of the code if I have no idea where to put it. This was a poorly done tutorial. Sorry.

You may think I'm an idiot and should'nt be learning this stuff at my point of standing, but I have to start somewhere, and thats the purpose of a tutorial, to explain how, and it should be useable to even the less experienced.

I've already moved around my hud using the x, and y axis's, and your example looks very straight forward which is good. But again, I don't know how to activate TriApi.


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 04 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
Spinning Corpses Simple Fix
Half-Life | Coding | Snippets
By: darkPhoenix | Sep 05 2008
 
Where do we go from here
General | News
By: MIFUNE | Jun 09 2008
 
The Input/Output system
Half-Life 2 | Level Design
By: nazitaco | Dec 23 2007
 
Where do we go from here
General | News
By: Rob_F | Nov 22 2007
 
Rescaling Half-Life
Half-Life | Coding | Shared Tutorials
By: christoph | Nov 12 2007
 
GameUI
Half-Life 2 | Coding | Client Side Tutorials
By: Evil_j | Oct 29 2007
 
3 State Zoom For Any Weapon
Half-Life 2 | Coding | Server Side Tutorials
By: Ennuified | Oct 18 2007
 
Storing weapons on ladder
Half-Life 2 | Coding | Snippets
By: cct | Sep 07 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: DarkNight | Aug 28 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: deedok | Aug 20 2007
 

Site Info
296 Approved Articless
5 Pending Articles
3940 Registered Members
5 People Online (24 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!