openglmodelingcolladamultitexturing

OpenGL Modeling


I am trying to create program that will allow me to convert from Collada format to my own custom format (this part is easy and under control). What I want to do is the following.

1.) Find a way to draw a model given the exact data parsed from a Collada file. a.) A simple cube will generate 8 vertices, 36 normal's, and 12 texture coordinates, this is find but the only way OpenGL way I can find to draw this requires me to duplicate the vertices and normal's data so that match the amount of normal's.

2.) Find a way to implement multitexturing. a.) I have found tons of tutorials on this, but it seems that I can't find a way to actually use this. These functions do not seem to be built into my versions of openGL (I have tried this on 2 computers) and no one documents any required dll I may be missing.


Solution

  • A simple cube will generate 8 vertices, 36 normal's, and 12 texture coordinates,

    No, a simple cube has 8 positions, but a vertex is not just a position, but contains also all the other attributes. So there is in fact no vertex duplication happening, but you're right, that you'll have some redundancy in the attributes.

    Update to explain, why this is so

    A vertex is the whole vector of its attributes. Change one, and you have a completely different vertex.

    Suppose you have a vertex shader taking some set of purely abstract attributes and a texture coordinate

    #version 150
    
    attribute vec2 foobar;
    attribute vec4 fnord;
    attribute vec2 texcoord;
    

    and this vertex shader computes some position from those attributes, like say

    void main() {
        gl_Position = vec3(fnord.xw, dot(foobar,texcoord));
    }
    

    As you can see, the vertex position now directly depends on all the attributes. But of course other varyings may as well.

    To save redundant calculations, the GPU maintains a cache mapping from vertex attribute input to transformation stage/vertex shader output. If vertices are accessed by index indirection, then the cache actually uses the index as key.

    So keep in mind: If anything associated with a vertex changes, you change the whole vertex. And in modern OpenGL the attributes of the vertices, even the position, may end up doing very different things.

    These functions do not seem to be built into my versions of openGL

    Oh, they probably are part of your drivers, alright. You probably just didn't load them into your program. The OpenGL DLL covers only the very basic things. For everything else you must load the function pointers dynamically. Just use a nice wrapper like GLEW for this (to be obtained at http://glew.sourceforge.net).