Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL blend problem
    primarykey
    data
    text
    <p>I want to draw aquarium (container) standing on table. Walls of aquarium need to be blended.</p> <p>But, if I draw table first and then aquarium I get:<br> - looking from the up of the table: ok<br> - looking from the bottom of the table: wrong, I still see aquarium </p> <p>If I draw aquariun first and then table I get:<br> - looking from the up of the table: wrong, aquarium walls have no effect on the table (they affect the backgrounf, though)<br> - looking from the bottom of the table: wrong, I still see aquarium </p> <p>There is picture that explains it:</p> <p><a href="http://img213.imageshack.us/img213/6609/pictureem.jpg" rel="nofollow noreferrer">http://img213.imageshack.us/img213/6609/pictureem.jpg</a></p> <p>Code: main.cpp</p> <pre><code>int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); Cam.SetPrespective(); //---------------- GLfloat LightPosition0[]= { 0.0, 0.0, 0.2, 1.0f }; GLfloat LightAmbient0[]= { 0, 0, 0, 1.0f }; GLfloat LightDiffuse0[]= { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat LightSpecular0[]= { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient0); // Setup The Ambient Light glLightfv(GL_LIGHT0, GL_POSITION,LightPosition0); // Position The Light glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse0); // Setup The Diffuse Light glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular0); // Setup The Diffuse Light glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //---------------- glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light glLightfv(GL_LIGHT2, GL_POSITION,LightPosition); // Position The Light glLightfv(GL_LIGHT2, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light drawContainer(); //container drawn first in this example //.. draw other things drawTable(); drawGround(); /* //.. draw other things drawTable(); drawGround(); drawContainer(); //container drawn last in this example */ CheckKeys(); if(mouse) { CheckMouse(); } return TRUE; } void drawTable() { glColor3f(1.0f, 0.5f, 1.0f); GLfloat cx = MIN_X+(MAX_X-MIN_X)/2.0f; GLfloat cy = MIN_Y-0.1f; GLfloat cz = MIN_Z+(MAX_Z-MIN_Z)/2.0f; GLfloat cr = sqrt((MAX_X-MIN_X)*(MAX_X-MIN_X)+(MAX_Z-MIN_Z)*(MAX_Z-MIN_Z))*0.85f; int th = 5.0f; //centerPieceThickness drawCylinder(cx,cy,cz,th,cr); glColor3f(0.7f, 0.5f, 0.5f); drawCylinder(MAX_X+cr*0.155f, cy-th, MAX_Z+cr*0.155f, 25*th, cr*0.035f); drawCylinder(MAX_X+cr*0.155f, cy-th, MIN_Z-cr*0.155f, 25*th, cr*0.035f); drawCylinder(MIN_X-cr*0.155f, cy-th, MIN_Z-cr*0.155f, 25*th, cr*0.035f); drawCylinder(MIN_X-cr*0.155f, cy-th, MAX_Z+cr*0.155f, 25*th, cr*0.035f); } void drawGround() { int th = 5.0f; GLfloat cx = MIN_X+(MAX_X-MIN_X)/2.0f; GLfloat cy = MIN_Y-0.1f; GLfloat cz = MIN_Z+(MAX_Z-MIN_Z)/2.0f; GLfloat cr = sqrt((MAX_X-MIN_X)*(MAX_X-MIN_X)+(MAX_Z-MIN_Z)*(MAX_Z-MIN_Z))*8.5f; glColor3f(0.0f, 0.6f, 0.0f); drawCylinder(cx,cy-26*th,cz,10.f,cr); } void drawContainer() { glColor3f(0.2f, 0.2f, 0.2f); drawCuboid(MIN_X-0.5, MAX_X+0.5f, MIN_Y-0.5, MIN_Y+0.5, MIN_Z-0.5f, MIN_Z+0.5f); drawCuboid(MIN_X-0.5, MAX_X+0.5f, MIN_Y-0.5, MIN_Y+0.5, MAX_Z-0.5f, MAX_Z+0.5f); drawCuboid(MIN_X-0.5, MAX_X+0.5f, MAX_Y-0.5, MAX_Y+0.5, MIN_Z-0.5f, MIN_Z+0.5f); drawCuboid(MIN_X-0.5, MAX_X+0.5f, MAX_Y-0.5, MAX_Y+0.5, MAX_Z-0.5f, MAX_Z+0.5f); drawCuboid(MIN_X-0.5, MIN_X+0.5f, MIN_Y-0.5, MAX_Y+0.5, MIN_Z-0.5f, MIN_Z+0.5f); drawCuboid(MIN_X-0.5, MIN_X+0.5f, MIN_Y-0.5, MAX_Y+0.5, MAX_Z-0.5f, MAX_Z+0.5f); drawCuboid(MAX_X-0.5, MAX_X+0.5f, MIN_Y-0.5, MAX_Y+0.5, MIN_Z-0.5f, MIN_Z+0.5f); drawCuboid(MAX_X-0.5, MAX_X+0.5f, MIN_Y-0.5, MAX_Y+0.5, MAX_Z-0.5f, MAX_Z+0.5f); drawCuboid(MIN_X-0.5, MIN_X+0.5f, MIN_Y-0.5, MIN_Y+0.5, MIN_Z-0.5f, MAX_Z+0.5f); drawCuboid(MIN_X-0.5, MIN_X+0.5f, MAX_Y-0.5, MAX_Y+0.5, MIN_Z-0.5f, MAX_Z+0.5f); drawCuboid(MAX_X-0.5, MAX_X+0.5f, MIN_Y-0.5, MIN_Y+0.5, MIN_Z-0.5f, MAX_Z+0.5f); drawCuboid(MAX_X-0.5, MAX_X+0.5f, MAX_Y-0.5, MAX_Y+0.5, MIN_Z-0.5f, MAX_Z+0.5f); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glColor4f(0.5f,1.0f,1.0f,0.12f); drawCuboid(MIN_X,MAX_X,MIN_Y,MAX_Y,MIN_Z,MAX_Z); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload