GLIM: OpenGL Immediate Mode for OpenGL 3.0

Hi there

A few weeks ago i wrote a library that allows to render geometry very similar to OpenGL’s immediate mode, but does so without any deprecated function. This means especially, that it requires you to use GLSL shaders with generic vertex attributes, ie. a purely shader-based approach.

One reason for me to write this library, was that i use generic vertex attributes with VBOs but usually the old-style glNormal / glTexCoord, when using immediate mode, because using generic vertex attributes with OpenGL’s immediate mode is pretty annoying. So my library makes this very easy.

After using it for a while i found it worked really well, and thought i should share it with other gl users, that want to break free from the fixed function pipeline.

It can be downloaded here: GLIM

The readme included gives a more detailed explanation. A small example on how GLIM works:

// instanciate a GLIM object whenever you need one
GLIM glim;

// set gl states

// begin some geometry with the current state
glim.BeginPart ();

// set some vertex attribute to a start value
glim.Attribute4ub ("Color", 255, 0, 0, 255);

// begin a certain primitive type (just as glBegin)
glim.Begin (GLIM_LINES);
// render one line
glim.Vertex (0, -1);
glim.Vertex (0, 1);

// render next line with different color
glim.Attribute4ub ("Color", 255, 255, 0, 255);

// render another line
glim.Vertex (-1, 0);
glim.Vertex (1, 0);

glim.End ();

// end rendering with the current state
glim.EndPart ();

// change gl states and possibly render more

As you can see, GLIM really only handles geometry. It does not bother about gl states or anything else. That’s the reason why it is so easy to just plug it into existing code. It does one thing and nothing more.

GLIM is released as full source code (you need to compile it yourself, but that should be really easy) and you are free to use and modify it as you wish.

Let me know what you think about it.

Sounds nice, especially for a beginner going straight to GL 3.1.
Your website date for this news seem 1 year off … 12.03.2008 :slight_smile:

Ooops, copy&paste :wink:

Nice. My approach for this is a bit different:

//-----------[ immediate-mode drawing ]----------------------------------------------[
void ilImmBegin(int NumVertsPerPrim1234,const short* vtxDecl); // start immediate mode, with expected type of primitives (1=points, 2=lines, 3=triangles, 4=quads and triangles). Each vertex has the same format, specified by vtxDecl. vtxDecl MUST NOT be NULL! vtxDecl must stay valid at least until ilImmEnd() - so don't put it on the thread's stack if the stack will be overwritten before ilImmEnd. 
void ilImmBegin(int NumVertsPerPrim1234,const short* vtxDecl,int MaxNumPrimitives);
void ilImmEnd(); // flush and end drawing this set of immediate-mode primitives
void ilImmFlush();// flush drawing, expecting to continue drawing imm-mode primitives. Useful if you want to change an uniform-value in-between a range of primitives
void ilImmPoint(const void* vtx1); // add one vertex, defining a point
void ilImmLine(const void* vtx12); // add two vertices, defining a line. vtx12 contains both vertices in a contiguous range of memory
void ilImmLine(const void* vtx1,const void* vtx2); // like above, but the two vertices can be from different ranges of memory
void ilImmTriangle(const void* vtx123); // add three vertices, defining a triangle. Contiguous range of memory
void ilImmTriangle(const void* vtx1,const void* vtx2, const void* vtx3); // like above, but different mem-ranges
void ilImmQuad(const void* vtx1234); // add four vertices, defining a quad. They get internally split into two CW triangles. 
void ilImmQuad(const void* vtx1,const void* vtx2, const void* vtx3,const void* vtx4); // like above, but different mem-ranges

void ilImmDrawArray(int NumPrimitives,int NumVertsPerPrim1234,const short* vtxDecl,const void* data);

the Begin() takes info what primitive-types we’ll draw, and a vertex-declaration array (elements in it mean “attrib0 is 3 floats, followed by attrib7 is 4ubyte-color, followed by attrib9 is 2 half-floats”. This decl-array can show how many bytes a vertex’s attribs take. Then, the subsequent calls specify the vtx-attrib data of each vertex required for a primitive.