Results 1 to 5 of 5

Thread: OpenGL 3 and color transitions

  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
    Senior Member Regular Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    138
    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
    ---------------------------------------------------------
    The OpenGL and VULKAN Podcast ( OpenGL2GO ) : OpenGL & Vulkan Podcast
    ---------------------------------------------------------
    timbling.com - Indie TeamUp

  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
    Senior Member Regular Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    138
    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
    ---------------------------------------------------------
    The OpenGL and VULKAN Podcast ( OpenGL2GO ) : OpenGL & Vulkan Podcast
    ---------------------------------------------------------
    timbling.com - Indie TeamUp

  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 =/

Similar Threads

  1. Rainbow color band and color palettes in OpenGL?
    By rakeshthp in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 01-15-2013, 01:57 AM
  2. Image Transitions...
    By Ehsan_Liverpool in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-08-2011, 07:14 AM
  3. High color/true color troubles on Win2000
    By Lelik in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-22-2004, 04:39 AM
  4. Smooth texture-transitions..
    By jonn in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-20-2001, 01:03 AM
  5. color buffer color as source for register combiners
    By Kosta in forum OpenGL: General
    Replies: 1
    Last Post: 07-11-2000, 09:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean