PDA

View Full Version : OpenGL 3 and color transitions



Leskovar
01-13-2013, 08:30 AM
Hello everyone.
I am new to OpenGL and i require help...

I am trying to draw a triangle where every top is colored in a different color...
The current code that I have is :

int buf2;
Vector3[] vertices2 = new Vector3[3];

vertices2[1] = new Vector3(1f, -1f, 0f);
vertices2[2] = new Vector3(-1f, -1f, 0f);
vertices2[0] = new Vector3(0f, 1f, 0f);


GL.GenBuffers(1, out buf2);
GL.BindBuffer(BufferTarget.ArrayBuffer, buf2);
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
new IntPtr(vertices2.Length * Vector3.SizeInBytes),
vertices2, BufferUsageHint.StaticDraw);


GL.Clear(ClearBufferMask.ColorBufferBit);

GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTarget.ArrayBuffer, buf2);
GL.Color3(Color.Yellow);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
GL.DrawArrays(BeginMode.Triangles,0,3);
GL.DisableVertexAttribArray(0);
GL.SwapBuffers();


This gives me a yellow triangle. Now I wonder how to color each top differently with colors transitioning one from another as you get closer to some top....

uwi2k2
01-13-2013, 09:06 AM
hi,

there ist not mutch you need to do.

the same way that you set the vertex attrib pointer
you can set the color pointer. color data is also just values in an array ...

and you are done ...

cu
uwi

Leskovar
01-13-2013, 09:25 AM
Thanks for your repsonse.

I have removed the GL.Color3() function and added the following code below GL.VertexAttribPointer():

var colorData = new float[9] { 100, 200, 150, 120, 150, 160, 20, 80, 190 };
GL.ColorPointer(3, ColorPointerType.Float, 0, colorData);

But it still doesnt work...

uwi2k2
01-13-2013, 10:00 AM
hi,

you canīt mix the input data from a VBO and a array ..
make 2 arrays for vertex and color .. or put them in one array and make a VBO of it.

cu
kai

Leskovar
01-13-2013, 10:35 AM
Sorry but I am desperate...
I have no clue how to do that, If you could please write me the code that does that I would be more then grateful =/