Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Transparent effect help

  1. #1
    Junior Member Newbie
    Join Date
    May 2009
    Posts
    2

    Transparent effect help

    `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();
    }

  2. #2
    Intern Contributor
    Join Date
    Mar 2008
    Location
    Singapore
    Posts
    67

    Re: Transparent effect help

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •