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
    Member 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!

Similar Threads

  1. Transparent Texture Effect
    By H.Stony in forum OpenGL: Basic Coding
    Replies: 18
    Last Post: 02-18-2005, 05:28 AM
  2. Question about texture transparent effect
    By CGDeveloper in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 06-13-2003, 02:53 AM
  3. Transparent
    By Kronos259 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-06-2003, 03:48 PM
  4. Replies: 4
    Last Post: 01-08-2002, 03:34 PM
  5. overlaying transparent and non transparent bitmaps
    By dodgyposse in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-13-2000, 01:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean