Results 1 to 2 of 2

Thread: Drawing Colored Cube

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1

    Drawing Colored Cube

    Hi,
    I have recently started coding on opengl ES 2.0, and very new to this field. Actually I want to draw colored cube on android such that each face will have different color. However I am only able to do single color shading using following fragment shader
    precision mediump float;
    void main() {
    gl_FragColor =vec4(1.0,0.0,0.0,0.0) ;
    }
    Can anybody suggest how to make multicolor shader?
    Also if anybody could provide sample code(Android) for reference, it would be really helpful.
    Thanks,

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Drawing Colored Cube

    You would need to add a per-vertex attribute to your mesh data to specify the color at each vertex. This also means that you can't share vertices between faces as you may be doing right now.

    Once you've done that, you would change the shader so that the vertex shader copies the per-vertex color into a 'varying' parameter - which the fragment shader would then copy into the gl_FragColor.

    If what I'm saying is too complicated for you to understand, then you'll need to go and read some OpenGL tutorials - or possibly buy a copy of "OpenGL(R) ES 2.0 Programming Guide" to study from. Detailed descriptions at this fundamental level are really beyond the scope of what we can teach you in a forum post - it takes an entire book to explain it all - and I don't have enough time at my disposal to type that much! We could give you example code that you could just mindlessly copy - but then you'd get stuck again at the very next thing you tried to do.

    So I strongly recommend getting a book to learn from. When you get stuck on really complicated things that books don't cover - then by all means, come back here and ask.

    -- Steve

Similar Threads

  1. Cube with holes
    By FrEaKmAn in forum Developers Coding:Beginner
    Replies: 1
    Last Post: 04-18-2011, 05:06 PM
  2. draw 3D cube
    By gandrakar in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 1
    Last Post: 06-14-2010, 01:02 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
  •