Results 1 to 3 of 3

Thread: two different colors for in and out sides

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2007
    Location
    San Francisco, CA
    Posts
    2

    two different colors for in and out sides

    Hello,

    Thanks to forums like this one, I managed (I am not a programmer, but someone who needs to display data) to write a nice OpenGL program that draws a complex hollow object, for which I have the vertex data. I got it to work nicely with shade, lighting and all that, but now I need to display different colors for the inside and the outside of my object.

    I read that this can be achieved with backface culling and drawing my polygons twice, once CCW and the other CW. However, I am finding some mutually contradicting advise. Thus, before I jump into modifying my code, I wondered whether anyone could share some words of wisdom on this, ideally showing me an example code, which is the way I learned to code myself

    Thanks a million,

    Marcelo

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: two different colors for in and out sides

    If you use materials (not just color) then you can simply define different materials for front and back faces.

    Rendering polygons twice is not a bad idea, too. If you don't have a lot of vertices it will be as fast as single pass.

  3. #3
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: two different colors for in and out sides

    Use two sided lighting where you specify a backface material and the winding flips the normal and changes the material.... OR do it yourself, flipping the normals (use duplicate attributes) and apply pposite face culling.

    Some drivers will handle this very simply and elegantly with optimization, others will pretty much do in the driver what you would do in your application.

    Two sided lighting tended to be one of those premium features manufacturers reserved for high end cards so they can charge a premium for Quadro DCC class hardware. It MAY be really slow on a gaming card for no reason other than marketing & product differentiation.

    So, in conclusion it can pay to implement BOTH systems because on the high end two sided lighting can be fast especially on modern hardware and Quadro class DCC platforms, but may be unacceptably slow on very capable gamers class hardware.

    There is a third way involving shaders & doing your own lighting but that's probably advanced for you. It is attractive because it basically implements two sided hardware lighting in a simple shader for all platforms.

Similar Threads

  1. Replies: 3
    Last Post: 06-19-2016, 08:11 AM
  2. show different colors on the 2 sides of a polygon
    By jyoung77 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-14-2003, 01:41 AM
  3. How to display two different colors on two sides of a triangle?
    By loginlog in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-23-2003, 10:37 PM
  4. TWO SIDES
    By Dimae in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-17-2001, 03:52 AM
  5. Front and Back sides with different colors
    By calbuq in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-20-2000, 04:23 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