OpenGL: MVP

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • OpenGL: MVP

      I'm using opengl 3.3, glm, glfw

      I've continued my adventures with OpenGL and am looking to draw multiple objects each independent of each other. For example I have a class drawObject and during each update or render I will call all the drawObjects relevant function. I am hoping to have a vector of these objects and each render to do the pre render stuff necessary and then iterate through the vector and call the render function for each object. The conceptual problem I'm faced with is: Do I store each object with a model matrix that I change for each object based on its movement (seems somewhat costly) and then multiply this by a global ProjectionView matrix or is there someway to store a transformation for each object like in GCC4. Moreover would I then pass PV matrix to the vertex shader globally and then send in the model matrix per object and calculate them in the shader, would I send in the model matrix via glUniformMatrix4fv or as something else?

      I am also trying to use indices as well, although I'm not entirely sure how these work with multiple objects to be drawn, I'm guessing I use them for each object and use glDrawElements for each object as well.

      I'm probably going to give this method a try, although it seems like I am missing something I just don't know what.

      Sorry if I've explained it poorly, just writing this out has given me a couple of ideas about how to proceed, I'll try post some source later and the results of my experiment.
    • There are many different ways to do this, in the end you will need to have a transformation of each individual object though.

      If you are using the fixed function pipeline you could simply use glMultMatrixf in model_view mode, however to get your matrix into the shader program you will have to pass it as a uniform. Mind you there are alot of different ways for accomplishing this, using uniforms are not the only way.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • I'm going for a programmable pipeline as that seems to be the modern way to do things and as far as I'm aware its more supported in later Opengl versions?

      I managed to do it, although it is somewhat unrefined, using a Model matrix for each object and then passing in the view and projection matrix before calling render on the objects and for each object using glUniformMatrix4fv to pass in my Model matrix. If I just apply transforms to this model matrix for each object at each update if needed, will it be too expensive memory wise for each piece of geometry to have its own matrix. Maybe I could do something using the scene graph with common transformations that also apply to the children?

      Thanks for the reply, I was just curious to see if I was vaguely on the right track which seems to be the case although I imagine that there are some serious optimizations that could be done.
    • The fixed function pipeline IS deprecated, but still supported through a compatibility mode, it is not recommended to begin learning in FF as it is slowly going to fade completely away leaving PP only, although I doubt it for a long time, some people argue that FF is easier to learn however PP when started from scratch without any bad FF habits is fairly easy to get into, plus it is much more powerful and future friendly.

      Take a look at this site for a good PP set of tutorials OGLDev, It says for Linux but if you are on Win32 it will work just the same.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz