0

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • *These (multitexturing) functions...* which functions? Are you referring to the opengl fixed pipeline multitexturing (glTexEnv, etc)? Modern OpenGL would do multitexturing in a shader, which I find is more intuitive than messing with the texture environment settings. – Tim Sep 21 '12 at 21:24
  • On point 1: This should be fairly straightforward. So, how much OpenGL do you actually know? – Shahbaz Sep 21 '12 at 21:38
  • How would you do it in a shader if you don't mind me asking? I'm pretty new to openGL and it's rather unintuitive. Most of the function I have tried orient around things like glActiveTexture() or use some GL_TEXTURE0 enum. I'm not sure of all the functions, honestly I've been trying it for a while now and they just don't seem to be part of the standard OpenGL package or gult. – Benjamin Danger Johnson Sep 21 '12 at 21:40
  • I'm not exactly sure how easy it is to use multiple arrays of different sizes. Maybe this was changed in v4, but I have been using v3 and I don't see a way without duplicating data for interleaving. – Benjamin Danger Johnson Sep 21 '12 at 21:41
  • You can't use arrays of different sizes. All arrays must be the same size, and thus you will have some duplicate data. – Tim Sep 21 '12 at 22:00
  • Regarding how to do it in shader, how much information do you know already? Do you know how to do single texturing in a shader? If not you might want to start with some basic tutorials. – Tim Sep 21 '12 at 22:01
  • I see, that is very disappointing about the arrays as it means I will have to duplicate the set of vertices roughly 4 times just to render a cube. But if there is no way to avoid that, at least I can stop researching it. As far as how to do it with shaders, could you post a link to a tutorial so I can give you credit for the answer. – Benjamin Danger Johnson Sep 21 '12 at 22:14
  • One other thing about using interleaved arrays, I see on this website: http://www.opengl.org/wiki/Vertex_Buffer_Object#Vertex_buffer_offset_and_stride that someone used a custom object that stored several small arrays for vertex data. Would it be possible for me to do this, but instead of assigning a new array to vertex, just giving it a pointer to the another array in a list? My idea is to have the 8 points in an array of arrays, and just use the Collada indices to specify which point should be assigned to the Vertex object. I don't think it will work with pointers, but i thought i would ask – Benjamin Danger Johnson Sep 21 '12 at 22:29
  • What have you tried? What does your code look like? What doesn't work with what you've tried? – George Stocker Sep 24 '12 at 00:35
  • at the moment I have been sticking to tutorials, I am still in the design phase of this and I am asking this as a research question. – Benjamin Danger Johnson Sep 24 '12 at 15:25

1 Answers1

0

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).

Community
  • 1
  • 1
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • so you would suggest simply duplicating the positions and texture coordinates so that I have enough to match the normal count? I must admit I hate this solution but the only way around it is to use the depreciated glBegin and glEnd stuff (basically just draw a list of triangles.) – Benjamin Danger Johnson Sep 22 '12 at 03:47
  • @BenjaminDangerJohnson: Yes, this is exactly what you *must* do. I do understand your disliking of it, but this is not only how OpenGL works, but how GPUs are wired internally. To save *redundant* calculations GPUs maintain a cache of tuples of the last dozen or so unique vertex attribute combinations and if that combination appears again, then the result of the computation (of the vertex shader) are fetched from the cache instead of recomputed. Similar for just indices if using glDrawElements. So while it might look like redundancy on first look, it actually saves huge amounts of redundancy. – datenwolf Sep 22 '12 at 08:44
  • okay first, thanks for clarify the vertex stuff (although I already knew what one was, I just prefer to use the term vertex instead of point although it is wrong.) and second, if I use shaders, is it possible for me to have multiple shaders for the same model? For example, what if I wanted to have a textured model (I guess this uses the vertex shader) along with bumpmaps and reflectivity (I know it's silly to do all three but this is an example.) I just hope by doing this I avoid having to check if the properties are present on every call and only use them on specific models. – Benjamin Danger Johnson Sep 23 '12 at 04:25
  • @BenjaminDangerJohnson: In each shader stage you can install exactly one shader. Vertex and fragment shaders are mandatory since OpenGL-3 core, geometry and tesselation are optional. But shaders are later linked into *programs* and it is perfectly possible, valid and recommended to share common shaders across multiple programs. So you could have 1 skeleton animation vertex shader, and use it together in several programs, each using a different fragment shader. – datenwolf Sep 23 '12 at 08:16