PDA

View Full Version : Transparent effect help



krishnachinya
05-20-2009, 04:03 AM
`m working on a undergraduate project that is diffraction through a prism,i`m having difficulty in creating glass or transparent effect for the prism..please can some one help me to create transparent effect..

if i use this functions

glEnable(GL_BLEND);
glBlendFunc(0.1,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);

prism will get disappeared..so can some help regarding this..

here is source code for drawing the prism...
please help me in creating transparent effect.


#include <stdlib.h>
#include <GL/glut.h>

GLfloat vertices[][3] = {{0.7,0,0.35},{0.7,-0.4,-0.35},{0.7,0.4,-0.35},{-0.7,0,0.35},{-0.7,-0.4,-0.35},{-0.7,0.4,-0.35}};
GLfloat normals[][3] = {{0.7,0,0.35},{0.7,-0.4,-0.35},{0.7,0.4,-0.35},{-0.7,0,0.35},{-0.7,-0.4,-0.35},{-0.7,0.4,-0.35}};

void polygon(int a, int b, int c , int d)
{
// draw a polygon via list of vertices
glBegin(GL_POLYGON);
glColor3f(1,0,0);
glNormal3fv(normals[a]);
glVertex3fv(vertices[a]);
glColor3f(1,1,0);
glNormal3fv(normals[B]);
glVertex3fv(vertices[B]);
glColor3f(0,0,1);
glNormal3fv(normals[c]);
glVertex3fv(vertices[c]);
glColor3f(0,1,1);
glNormal3fv(normals[d]);
glVertex3fv(vertices[d]);
glEnd();
}

void prism(void)
{

polygon(0,1,2,0);
polygon(3,4,5,3);
polygon(0,2,5,3);
polygon(0,1,4,3);
polygon(1,2,5,4);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(250,1,1,0);
glRotatef(200,1,1,0);
glRotatef(90,1,0,0);
prism();
glFlush();
glutSwapBuffers();
}
void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Prism");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glShadeModel(GL_SMOOTH);
glutMainLoop();
}

matchStickMan
05-20-2009, 08:01 PM
I usually use

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

for blending. try it and see if it works.

btw in the sample code that you posted above, you are not using blending at all!