Thursday, March 27, 2008

Thinking in Triangles and vertex

Well lately I been looking into the wonderful world of openGL. Making 3d programs seem easy until you start digging in the books and making the code. So as part of a quick warning, coming from a noob in the library, you have to start thinking in triangles and vertex. You could also have quads but basically the graphic card (the wonderful thingy in your pc that does most of the magic of the grafics) works with triangles. A relief is that you don't have to make all the libraries for drawing objects in a 3d space, so some rotations and perspective are already programed, yay. Also each vertex can be colored and each triangle textured and the library along with the graphic card does the work of making it look 3d. YET this doesn't mean your just going tell the program to load an object just like that and have a world done without making first an engine. The basic is, all triangles have to be declared, a triangle consists of 3 vertex and each vertex consists of 3 opengl floats, so its a lot of information per triangle, but thats where the magic of opengl pipeline works with, it connects directly to the grafic card so that large amount of information can pass quickly to the grafic card prossesed and from there to your monitor. A prosses that is done quite fast considering most of todays games have thousands to sometimes millions of vertex in each frame that are constantly changing.

here is a bit of simple code
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
Of course the complete code for displaying an opengl window is more complex. and varies depending on OS, but I will dedicate this blog just to give a heads up idea of what your gonna get into the future, so your not surprised later. So to start making your work easy you will need arrays of vertex and loops to display thousands of triangles efficiently and without loosing your head hard coding shapes.

that for now and back to the code.

No comments: