Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: GLIM: OpenGL Immediate Mode for OpenGL 3.0

Hybrid View

  1. #1
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    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:

    Code :
     
    // 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.
    Jan.
    GLIM - Immediate Mode Emulation for GL3

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,580

    Re: GLIM: OpenGL Immediate Mode for OpenGL 3.0

    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

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: GLIM: OpenGL Immediate Mode for OpenGL 3.0

    Ooops, copy&paste ;-)
    GLIM - Immediate Mode Emulation for GL3

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,290

    Re: GLIM: OpenGL Immediate Mode for OpenGL 3.0

    Nice. My approach for this is a bit different:

    Code :
    //-----------[ 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •