Note that there are some explanatory texts on larger screens.

plurals
  1. PODraw a penetrable object in opengl
    primarykey
    data
    text
    <p>How to draw a cube which is penetrable using opengl?</p> <pre><code>#include &lt;GL/glut.h&gt; // GLUT, include glu.h and gl.h double rotate_y; double rotate_x; double zoom; void solidSphere(double r) { glutSolidSphere(r, 50, 50); } float ALPHA = 0.6; float trans = 0.1; void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_2D); glLoadIdentity(); glTranslatef(-2.2f, 0.31f, -7.0f); glScalef(1.0, 1.0, 1.0); glRotatef(rotate_x, 1.0, 0.0, 0.0 ); glRotatef(rotate_y, 0.0, 1.0, 0.0 ); glColor4f(1,0,0, ALPHA); glutSolidCube(2); glLoadIdentity(); glTranslatef(2.2f - trans, 0.31f, -7.0f); glScalef(1.0, 1.0, 1.0); glColor3f(0,1,0); glutSolidCube(1); glutSwapBuffers(); } // ---------------------------------------------------------- // specialKeys() Callback Function // ---------------------------------------------------------- void specialKeys( int key, int x, int y ) { // Right arrow - increase rotation by 5 degree if (key == GLUT_KEY_RIGHT) trans -= 0.1; // Left arrow - decrease rotation by 5 degree else if (key == GLUT_KEY_LEFT) trans += 0.1; else if (key == GLUT_KEY_UP) rotate_x += 5; else if (key == GLUT_KEY_DOWN) rotate_x -= 5; else if (key == GLUT_KEY_INSERT) zoom *= (1.0 + 0.01); else if (key == GLUT_KEY_END) zoom *= (1.0 - 0.01); // Request display update glutPostRedisplay(); } void reshape(GLsizei width, GLsizei height) { if (height == 0) { height = 1; } GLfloat aspect = (GLfloat)width / (GLfloat)height; glViewport(0, 0, width, height); glOrtho(0.0, width, 0.0, height, 0, 50000); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.0f, aspect, 0.1f, 100.0f); } void initGL() { GLfloat sun_direction[] = { 0.0, 2.0, -1.0, 1.0 }; GLfloat sun_intensity[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat ambient_intensity[] = { 0.3, 0.3, 0.3, 1.0 }; glClearColor(0.1, 0.39, 0.88, 1.0); glColor3f(1.0, 1.0, 1.0); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_intensity); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, sun_direction); glLightfv(GL_LIGHT0, GL_DIFFUSE, sun_intensity); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective(90.0f, 2.0, 0.1f, 100.0f); } int main(int argc, char** argv) { rotate_y = 0; rotate_x = 0; zoom = 1.0; glutInit(&amp;argc, argv); glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640, 480); glutInitWindowPosition(50, 50); glutCreateWindow("cube and sphere"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(specialKeys); initGL(); glutMainLoop(); return 0; } </code></pre> <p>this code will draw two cubes one partial transparent and one completely opaque By right and left arrow key you can move green cube. I need that when green cube enters red cube(transparent) part of cube inside is also visible</p> <p>is it feasible ?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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