{"id":81,"date":"2013-11-08T15:46:23","date_gmt":"2013-11-08T15:46:23","guid":{"rendered":"\/\/3dbym.ru\/2013\/11\/rendering-obj\/"},"modified":"2013-11-08T15:46:23","modified_gmt":"2013-11-08T15:46:23","slug":"rendering-obj","status":"publish","type":"post","link":"https:\/\/3dbym.ru\/2013\/11\/rendering-obj\/","title":{"rendered":"Rendering OBJ"},"content":{"rendered":"
Let\u2019s see what you can do about getting this thing onscreen. If you turn to the CObj::Render() function in obj. cpp, you will see what it takes to get everything onscreen. The first thing to do is to activate and bind the texture. Make sure to check if the texture is valid before calling bind to avoid problems.<\/p>\n
Then you can start rendering. The first thing that happens is it checks to see which components are included in the model and picks a loop based on the result. There is a separate loop for every possible combina\u00adtion to improve the speed. In pseudo-code, the rendering code would look like the following code. Keep in mind the pseudo-code gives you only a basic layout of how a function should look. It should be obvious that the following code will not compile in a regular C\/C++ compiler.<\/p>\n
for(each vertex)<\/p>\n
if(normals are present)<\/p>\n
SendNormal(); if(texcoords are present)<\/p>\n
SendtexCoord();<\/p>\n
SendVertex()<\/p>\n
That would require two if statements for every vertex, which is a waste of processor time when you can do with but a couple for every frame. Instead, the structure is more like this:<\/p>\n
if(has normals and tex coords) for(each vertex)<\/p>\n
SendNormal()<\/p>\n
SendTexCoord()<\/p>\n
SendVertex() else if(has texcoords but not normals) for(each vertex)<\/p>\n
SendTexCoords()<\/p>\n
SendVertex();<\/p>\n<\/p>\n
<\/p>\n
<\/p>\n