colors - how should I go about drawing one side coloured triangles opengl -


i worked out how read in element color collada .dae files i'm not sure how go rendering colored elements in opengl. render elements use gldrawelements

two colored triangles can overlap each 1 face colored. how go implementing this? how choose side of triangle shows color?

from know xml "sid" attribute identifies side of triangle colored based on order of vertices , appear software producing files chooses use 2 separate triangles 1 each colored side have normal , position vertices data being plotted need able apply colors elements.

it sounds model made of single-sided triangles, two-sided surface represented 2 single-sided surfaces facing in opposite directions. draw properly, need use opengl's built-in backface culling draw correct side of each triangle.

opengl makes distinction between "front" , "back" of triangle, based on order of vertices. default, "front" side vertices appear in counterclockwise order. can change clockwise calling glfrontface(gl_cw), sake of argument i'll assume you're using counterclockwise since it's default.

from know xml "sid" attribute identifies side of triangle colored based on order of vertices

it's not clear, above, whether 2 sides of surface stored in file vertices in opposite order, or if both triangles stored vertices in same order , "sid" attribute tells 1 front , back. i'm going assume opposite sides in opposite order; if that's not true, you'll need use "sid" decide ones reverse when building vertex array opengl.

if 2 sides of surface stored vertices in opposite order, both follow same counterclockwise rule. suppose have surface that's red on 1 side , blue on other. looking @ red side, vertices of red triangle appear in counterclockwise order, , of blue triangle clockwise. if turn around @ blue side, blue triangle's vertices counterclockwise , red's clockwise. based on this, opengl can determine you're looking @ "front" of 1 triangle , "back" of other.

all need do, then, tell opengl draw front side of each triangle:

glenable(gl_cull_face); glcullface(gl_back); 

this makes opengl "cull" (not draw) triangle if side seen "back" one. when viewer looking @ red side of surface, red triangle drawn (since "front" facing camera), , blue triangle not (since "back" facing camera). when viewer looking @ blue side of surface, blue triangle drawn , red 1 not. 2 triangles overlap, 1 or other drawn, never both.

with backface culling enabled, shouldn't need other special handling two-sided surfaces. draw each triangle own color, , let opengl cull out ones facing wrong way.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -