Results 1 to 2 of 2

Thread: Drawing Colored Cube

  1. #1
    Email address no longer exists
    Join Date
    Jan 2011

    Drawing Colored Cube

    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.

  2. #2
    Senior Member
    Join Date
    May 2010

    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. draw 3D cube
    By gandrakar in forum OpenGL ES
    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
Proudly hosted by Digital Ocean