Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You mistake lies in your lack of understanding of OpenGL. <strong>OpenGL is not a scene graph!</strong> It's best to think OpenGL to be a set of drawing tools to paint on a canvas called the frame buffer.</p> <p>So in using OpenGL you must put your mind in a state similar to if you's draw a picture with pencils, eraser, brush and paint. First you prepare your tools: Textures are like "sheets of colour", meshes of vertices are like some delicate "brush".</p> <p>Like an artist the very fist step is to prepare your tools. You prepare your geometry (i.e. the meshes), if you use Vertex Buffer Objects you load them into fast memory with glBufferData, and your paint and dye, the textures. This is what you do in the "init" phase (I prefer to do this on demand, so that users don't see a "loading" screen).</p> <p>First you load all your objects (geometry in VBOs, textures etc.); you do this exactly once for each required object, i.e. once an object is prepared (i.e. complete) you don't have to re-upload it.</p> <p>Then in every drawing iteration for each object you want to draw you bind the needed OpenGL <em>objects</em> to their <em>targets</em>, then perform the drawing calls, which will then be performed using the currently bound objects.</p> <p>i.e. something like this, please use common sense to fill in the lacking functions in your mind:</p> <pre><code>struct texture; // some structure holding texture information, details don't matter here struct geometry; // structure holding object geometry and cross references texture *textures; geometry *geometries; texture * load_texture(char const *texture_name) { texture *tex; if( texture_already_loaded(textures, texture_name) ) tex = get_texture(texture_name); else tex = load_texture_data(textures, texture_name); return tex; } geometry * load_geometry(char const *geometry_name) { geometry * geom; if( geometry_already_loaded(geometries, geometry_name) ) geom = get_geometry(geometry_name); else geom = load_geometry_data(geometries, geometry_name) if( geom-&gt;texture_name ) geom-&gt;texture = load_texture(geom-&gt;texture_name); return geom; } void onetime_initialization() { for(geometry_list_entry * geom = geometry_name_list; geom ; geom = geom-&gt;next) geom-&gt;geometry = geometry_load(geom-&gt;name); } void drawGL() { glViewport(...); glClearColor(...); glClear(...); glMatrixMode(GL_PROJECTION); // ... glMatrixMode(GL_MODELVIEW); // ... for(geometry_list_entry * geom = geometry_name_list; geom ; geom = geom-&gt;next) { glMatrixMode(GL_MODELVIEW); // this is not redundant! glPushMatrix(); apply_geometry_transformation(geom-&gt;transformation); // calls the proper glTranslate, glRotate, glLoadMatrix, glMultMatrix, etc. glBindTexture(GL_TEXTURE_2D, geom-&gt;texture-&gt;ID); draw_geometry(geom); glMatrixMode(GL_MODELVIEW); // this is not redundant! glPopMatrix(); } // ... swapBuffers(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload