c# - Why should I use glTranslate? -


what's purpose of pushing/popping matrix translate shape when can sort of position math myself? can understand using said aforementioned matrices more difficult operations (rotation example), why translating specifically?

public void render()         {             positionx++;              gl.pushmatrix();             gl.translate(positionx, positiony, 0);              gl.matrixmode(matrixmode.modelview);             gl.loadidentity();              gl.begin(primitivetype.quads);              gl.vertex2(0, 0);             gl.vertex2(0 + widthx, 0);             gl.vertex2(0 + widthx, 0 + widthy);             gl.vertex2(0, 0 + widthy);              gl.popmatrix();              gl.end();         } 

versus

public void render()         {             positionx++;             gl.matrixmode(matrixmode.modelview);             gl.loadidentity();              gl.begin(primitivetype.quads);              gl.vertex2(positionx, positiony);             gl.vertex2(positionx + widthx, positiony);             gl.vertex2(positionx + widthx, positiony + widthy);             gl.vertex2(positionx, positiony + widthy);              gl.end();         } 

i don't think dumb question, altough answer might become clear work opengl more.

translating using gltranslate (or similar methods) can come in handy when want different order of transformations. changing vertex coordinates can work if translation first transformation want do. if want do, example, rotation, translation, rotation, have use matrix.

the main reason, however, not sending vertices gpu on every frame. extremely slow and, in fact, of gl.* method use deprecated. way done nowadays is:

  1. send vertex data the gpu once before begin rendering (remember can thousands of polygons or more).
  2. the gpu store data in internal memory (that's why have many mb/gb of ram on graphics card) , give id (e.g. 1).
  3. when rendering frame, tell gpu "draw stuff saved id 1". single opengl call - keep in mind every opengl call has cost (meaning time), fewer calls make, faster graphics be.

the same done textures, shaders , other things.

therefore, don't modify vertex data once send gpu (technically possible modify, it's not advisable performance reasons). if want transformations @ all, have use matrix.

as final note, i'll again you're using deprecated functionality, not bad learning basic concepts suppose, recommend moving current opengl (or @ least opengl 3) possible , know shaders, vertex buffers, vertex arrays , new shiny stuff.

tl;dr: yes, can yourself. it's better let graphics card because can lot faster. in fact, main reason having dedicated graphics card.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -