Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: OpenGL 3 and color transitions

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    3

    OpenGL 3 and color transitions

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

  2. #2
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98
    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
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    3
    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...

  4. #4
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98
    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
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    3
    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 =/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •