# RGBA formula

Hi there. I have a simple example and complicated(for me) question

Lets glimpse at example

glBegin(GL_TRIANGLES);
glColor3f(1.0,0.0,0.0);
glVertex3f( 0.0, 1.0, 0.0);
glColor3f(0.0,1.0,0.0);
glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0,0.0,1.0);
glVertex3f( 2.0, -1.0, 0.0);
glEnd();

Trivial, isn’t it?

In result i got triangle, which is filled with smooth color - Red, Green, Blue, all those colors mix together in the middle of the center

And now the questions. What is the formula, who describe color’s mixing behaviour?

Thanks in advance for any response!
Regards!

Del.

Originally posted by Delorean:
[b]Hi there. I have a simple example and complicated(for me) question

Lets glimpse at example

glBegin(GL_TRIANGLES);
glColor3f(1.0,0.0,0.0);
glVertex3f( 0.0, 1.0, 0.0);
glColor3f(0.0,1.0,0.0);
glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0,0.0,1.0);
glVertex3f( 2.0, -1.0, 0.0);
glEnd();

Trivial, isn’t it?

In result i got triangle, which is filled with smooth color - Red, Green, Blue, all those colors mix together in the middle of the center

And now the questions. What is the formula, who describe color’s mixing behaviour?

Thanks in advance for any response!
Regards!

Del.[/b]
Hello there,
Well you give the color values per vertex and opengl simply interpolates these value throughout the given polygon based on the famous gouraud model. Hace a google search on this and you will hve plenty of references on it. Actually there is a lot going on under the hood but opengl provides a nice interface to the programmers to keep them busy on the important stuff. Individual polygon vertices are clipped and then rasterizd to be projected on the screen etc.
Thanx
MMMovania

Thanks for your response MMMovania !

U see, i am writing research work about the OpenGL and i have to describe algorithms about various OpenGL processes. i have to find out whats going on in glColor3f function and how he makes that smooth colors transformation.

Maybe u also know any site, where is explained various opengl functions algorithms?

Thanks MMMovania,
Regards!

Del.

Maybe anyone else can help… ?

given 3 vertices v1, v2, v3 of a tria with function values f1, f2, f3. to calculate the function value at a point p:

1. connect p with each of the three vertices, thereby dividing the tria into three subtrias: T1 = (p, v2, v3), T2 = (p, v1, v3), T3 = (p, v1, v2)

2. calculate the area A1, A2, A3 for the subtrias T1, T2, T3 and the area A of the original tria.

3. the interpolated function value at p is f§ = A1/Af1 + A2/Af2 + A3/A*f3

…i’m not absolutely sure, but i think this works only if point p lies within the original tria…

…trying to insert an image … Hei, thanks for your reply RigidBody! This helps alot, but have still question.

How OpenGL choose that P points locality? As i understand, P point is located in that place, where all colours come together and colours from one subtrias wont cross the border to nearest subtrias area.

And P point is not in vertex bisectors point of intersection.

``````glBegin(GL_TRIANGLES);
glColor3f(1.0,1.0,1.0);
glVertex3f( 0.0,  1.0, 0.0);
glColor3f(1.0,1.0,1.0f);
glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.8f,0.3f,0.5f);
glVertex3f( 1.0, -1.0, 0.0);
glEnd();
``````

The pink colour is almost filled whole triangle.

What do you think RigidBody?

Thanks and Regards!
Del.

ok, look at this:

``````[img]http://www.t-roesener.de/scr/TriaOnScreen.gif[/img]
``````

you tell OpenGL what kind of view you want (glOrtho or gluPerspective, for example) and where you look at (with gluLookAt).

then you define the triangle vertices in 3d space using glVertex3f (…). OpenGL maps the vertices to pixel coordinates on the screen. in this example, we have a 1024x768 screen.

when the pixel coordinates of the 3 corner vertices have been calculated ((500,0) for vertex 1, for example). OpenGL uses an algorithm to determine which of all the screen pixels lie within the triangle.

and finally, for EACH pixel p which lies within the triangle on the screen, the color value is interpolated using the formula which i wrote down above.

Roger RigidBody!

Thanks for your assistance! you’re welcome although i hope that i didn’t just do your home work for you, did i?

Well… not really… i am writing bachelor about OpenGL. And i have to explain various OpenGL algorithms your reply saved hours for me and those hours are invaluable becouse of all other for me unexplored mathematical OpenGL solutions.

So probably soon i will return with another mathematical question…

Thanks RigidBody!
Ragards! Del.