Posted Monday, 1 June, 2009 - 10:37 by the Fiddler
IIRC = if I remember correctly
If you expect the lines to take part in the lighting equations, then yes. Otherwise, you can disable lighting when you draw the lines and use vertex colors instead.
Posted Monday, 1 June, 2009 - 10:44 by Soundbomber
I am happy enough for the lines to be a constant color and not take part in any lighting equations. How do I implement vertex colors? (Im am rendering using DrawElements)
Posted Monday, 1 June, 2009 - 11:01 by the Fiddler
Do you need the color to change per-vertex or is it enough to change once per DrawElements call?
If it is the former, you need to augment your vertex structure to hold color information. For example:
<StructLayout(LayoutKind.Sequential, Pack=1)>
Struct VertexPositionColor
Public Position AsVector3;
Public Color As Color4;
Public Shared ReadOnly SizeInBytes AsInteger = Marshal.SizeOf(GetType(VertexPositionColor))End Struct
(My VB.Net skills are a little rusty and I don't have a compiler installed, but I hope this makes sense)
You upload your vertices as before, taking care to specify the correct value for the size parameter ("number_of_vertices * VertexPositionColor.SizeInBytes").
Finally, you bind your VBO and call:
' Disable lighting, otherwise vertex colors will be ignoredGL.Disable(EnableCap.Lighting)' The last parameter indicates the offset of the relevant information inside the' VertexPositionColor structureGL.VertexPointer(3, VertexPointerType.Float, VertexPositionColor.SizeInBytes, IntPtr.Zero)GL.ColorPointer(4, VertexPointerType.Float, VertexPositionColor.SizeInBytes, Vector3.SizeInBytes)' Just like beforeGL.DrawElements(...)
Posted Monday, 1 June, 2009 - 11:13 by Soundbomber
I am currently using InterleavedArrayFormat.T2fC4fN3fV3f to hold my vertex colors, I thought that using interleaved arrays automatically takes care of the color/position/normal pointers?
Posted Monday, 1 June, 2009 - 11:27 by the Fiddler
Edit: as objarni asks, do you really need per-vertex colors?
In that case it's simply a matter of specifying the correct InterleavedArrayFormat for your vertex structure. InterleavedArrayFormat.T2fC4fN3fV3f implies a structure like:
<StructLayout(LayoutKind.Sequential, Pack=1)>
Struct VertexT2C4N3V3
Public TexCoords AsVector2;
Public Color As Color4;
PublicNormalAsVector3;
Public Position AsVector3;
Public Shared ReadOnly SizeInBytes AsInteger = Marshal.SizeOf(GetType(VertexT2C4N3V3))End Struct
Simply specify the colors you want before uploading the data with BufferData and it will work.
Edit 2: Just to clarify, GL.InterleavedArrays is just one way to create an interleaved array. GL.InterleavedArrays is a very limited function that gives you access to a few specific interleaved formats. GL.Vertex/Color/NormalPointer give you more flexibility (e.g. you can choose the order of the attributes or use multiple sets of texture coordinates). GL.VertexAttribPointer gives you ultimate flexibility: the vertex shader is free to interpret each attribute as it sees fit.
Posted Monday, 1 June, 2009 - 12:49 by Soundbomber
At the moment I am coloring all lines the same so no I don't need per vertex colors. At some point in the future however, I would like to color different face outlines with different colors and maybe hidden detail lines a different color. So I would like the flexibility.
Comments
Re: Line Color
You have to place the color into the interleaved array as a vertex attribute. ColorPointer is the function, IIRC.
Re: Line Color
Ok. I'm using lighting, do the line vertices need normals?
Scuse my ignorance but what does the IIRC abbreviation mean?
Re: Line Color
IIRC = if I remember correctly
If you expect the lines to take part in the lighting equations, then yes. Otherwise, you can disable lighting when you draw the lines and use vertex colors instead.
It depends on the effect you want to achieve.
Re: Line Color
I am happy enough for the lines to be a constant color and not take part in any lighting equations. How do I implement vertex colors? (Im am rendering using
DrawElements)Re: Line Color
Do you need the color to change per-vertex or is it enough to change once per
DrawElementscall?If it is the former, you need to augment your vertex structure to hold color information. For example:
(My VB.Net skills are a little rusty and I don't have a compiler installed, but I hope this makes sense)
You upload your vertices as before, taking care to specify the correct value for the size parameter ("
number_of_vertices * VertexPositionColor.SizeInBytes").Finally, you bind your VBO and call:
Re: Line Color
I am currently using
InterleavedArrayFormat.T2fC4fN3fV3fto hold my vertex colors, I thought that using interleaved arrays automatically takes care of the color/position/normal pointers?Re: Line Color
Soundbomber - given one outline-polygon, how many different colors are involved?
Re: Line Color
Edit: as objarni asks, do you really need per-vertex colors?
In that case it's simply a matter of specifying the correct InterleavedArrayFormat for your vertex structure.
InterleavedArrayFormat.T2fC4fN3fV3fimplies a structure like:Simply specify the colors you want before uploading the data with
BufferDataand it will work.Edit 2: Just to clarify,
GL.InterleavedArraysis just one way to create an interleaved array.GL.InterleavedArraysis a very limited function that gives you access to a few specific interleaved formats.GL.Vertex/Color/NormalPointergive you more flexibility (e.g. you can choose the order of the attributes or use multiple sets of texture coordinates).GL.VertexAttribPointergives you ultimate flexibility: the vertex shader is free to interpret each attribute as it sees fit.Re: Line Color
At the moment I am coloring all lines the same so no I don't need per vertex colors. At some point in the future however, I would like to color different face outlines with different colors and maybe hidden detail lines a different color. So I would like the flexibility.
Re: Line Color
Soundbomber: my advice to you is begin with the simplest thing (single color per polygon), that is what you need now.
When and if the time comes you want several different colors, change your code then. Just a humble advice.