Results 1 to 3 of 3

Thread: Combining Transparency and Light

  1. #1
    Newbie Newbie
    Join Date
    Jun 2014
    Posts
    2

    Question Combining Transparency and Light

    Hallo everybody,
    {sorry, my englich is yet poorer than my knowledge about OpenGL }

    I'm trying to combine transparency with kight effect(s), but everytime I enable light, transparenca ist lost, using OpneGL 3.

    ALPHA Values (transperrency) of all (relevant) colors are set to 0.5f, so I don't understand the phenomen.

    My main(...): // using '_' to see formatted code //

    int main( int argc, char* argv[] ) {
    _ glutInit( &argc, argv ); // initialize GLUT
    _ glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    _ glutInitWindowPosition( 5, 3 );
    _ glutInitWindowSize( currentWidth, currentHeight );

    _ if( glutCreateWindow(" <DESRIPTION> | Anonymus 2014") == GL_FALSE )
    _ exit( 1 );

    _ init();
    _ glutDisplayFunc( renderScene );
    _ glutReshapeFunc( reshape );
    _ glutKeyboardFunc( keyboard );
    _ glutSpecialFunc( specialFunc );
    _ glutMouseFunc( mousePressedOrRealeased );
    _ glutPassiveMotionFunc( mouseMotionReleased );
    _ glutMotionFunc( mouseMotionPressed );
    _ glutTimerFunc( msecs, animate, 0); // delay[mSec], Function Pointer, parameter

    _ glutMainLoop();

    _ return 0;
    }


    so after creating window 1st lights are configured:

    void init() {
    _ initLigths();
    _ loadGLTextures();
    _ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
    _ glEnable( GL_DEPTH_TEST );
    _ glClearDepth( 1.0 );
    _ userInfo_and_menu(); // my user outputs
    }

    void initLigths() {
    _ GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    _ GLfloat mat_shininess[] = { 50.0f };

    _ // 1st light ('0')
    _ GLfloat light0_position[] = { 1.0f, 1.0f, 1.0f, 0.0f },
    _ light1_position[] = { -1.0, -1.0f, 1.0f, 0.0f };
    _ //glClearColor( 0.0, 0.0, 0.0, 0.0 );
    _ glShadeModel( GL_SMOOTH );
    _ glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
    _ glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );
    _ // / ??
    _ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
    _ // ?? /
    _ glLightfv( GL_LIGHT0, GL_POSITION, light0_position );

    _ // 2nd light ('1')
    _ GLfloat light1_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    _ GLfloat light1_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    _ GLfloat light1_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    _ GLfloat spot_direction[] = { 1.0f, 1.0f, 0 };
    _ glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient );
    _ glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse );
    _ glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular );
    _ //glLightfv( GL_LIGHT1, GL_POSITION, light_position1 );
    _ glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
    _ glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5f );
    _ glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5f );
    _ glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2f );
    _ glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 41.0f );
    _ glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction) ;
    _ glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0f );
    _ //
    _ glEnable( GL_LIGHTING );
    _ glEnable( GL_LIGHT0 );
    _ glEnable( GL_LIGHT1 );
    }


    Rendering occurs with (partionally pseudocode)

    void reshape( int width, int height ) {
    _ if( changedViewAngle || currentWidth != width || currentHeight != height ) {
    _ if( changedViewAngle )
    _ changedViewAngle = false;
    _ else {
    _ currentWidth = width;
    _ currentHeight = height;
    _ }
    _ }
    _ glMatrixMode( GL_PROJECTION );
    _ glLoadIdentity();
    _ // define viewport
    _ glViewport( 0, 0, width, height ); // x,y of lower left corner

    _ gluPerspective( angle_degrees_gluPerspective,// y direction
    _ 1.0, // aspect ratio => field of view
    _ 0.7, 10.97 ); // zNear, zFar

    _ glMatrixMode( GL_MODELVIEW );
    }

    void renderScene() { // Code to be executed in every Frame
    _ glLoadIdentity (); // Reset / actual Model-/View-Transformations-Matrix
    _ // Camera
    _ gluLookAt( gluLookAt_eyeX,
    _ gluLookAt_eyeY,
    _ gluLookAt_eyeZ,
    _ 0.0, 0.0, 0.0, // centerX, centerY, centerZ of view
    _ gluLookAt_upX, // Camera View-Up Vector
    _ gluLookAt_upY, // i.e. the normale of
    _ gluLookAt_upZ ); // (upon) camera
    _ LIGHT_BLUE_CLEAR; // Background Color
    _ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    _ glPushMatrix();
    _ glTranslatef( 0, 0, // x, y (stay)
    _ -0.3f ); // z --> behind
    _ glRotatef( -1, 1.0f, 0, 0 );
    _ drawSomething(); // the background
    _ glPopMatrix();
    _ //
    _ glPushMatrix();
    _ glTranslatef( offsetX, offsetY, offsetZ );
    _ glRotatef( 13.7f, 0, 0.1f, 1.0f ); // 1.37 around y-, 13.7 around z- axis
    _ createObject1();
    _ glPopMatrix();
    _ //
    _ glPushMatrix();
    _ glEnable( GL_BLEND ); // works, but doesn't with light(s)
    _ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    _ glTranslatef( -7.1f, 6.77f, 0 );
    _ if( isMovableToLeft ) leftArrow( 0, 1, 1.3f, 0.59f );
    _ if( isMovableToTop ) topArrow( 0, 1, 1.3f, 0.59f );
    _ if( isMovableToRight ) rightArrow( 0, 1, 1.3f, 0.59f );
    _ if( isMovableToBottom ) bottomArrow( 0, 1, 1.3f, 0.59f );
    _ glPopMatrix(); // */
    _ glDisable( GL_BLEND );
    _ WHITE; // uses #define statement for color
    _ glutSwapBuffers();
    _ glFlush(); // clear buffer(s?)
    }


    and animation is done by

    void animate( int value ) {
    _ if( mousePressed || sleeping ) {} // don't animate
    _ else {
    _ updateValues();
    _ calculatePositions();
    _ }

    _ glutPostRedisplay(); // call renderScene() in any case

    _ // re-register Timer
    _ glutTimerFunc( msecs, animate, ++value ); // delay, Function Ptr, parameter
    }



    Would be very nice, if somebody could tell me what to change or how to do for combining light effects with transpareny, if possible.
    Thanks for your answers

  2. #2
    Member Newbie
    Join Date
    Sep 2013
    Posts
    31
    If you are really using OpenGL 3.x you must use shaders. But it seems that you are using OpenGL 1.x, I don't remember how to do that. Have you tried with GL_ALPHA_TEST insteed of using GL_BLEND?

  3. #3
    Newbie Newbie
    Join Date
    Jun 2014
    Posts
    2
    Thanks for your answer,
    perhaps this is v 1.x, but I don't know, because I used for basic structures some code fount in the internet and a very old book, often not commented or partionally only, and modified it. Only the code for creating my figures is written by me (didn't post it).

    Thanks for more responses

Similar Threads

  1. NSOpenGLView visual transparency vs. mouse transparency
    By hidefromkgb in forum OpenGL: macOS
    Replies: 1
    Last Post: 05-12-2015, 01:05 PM
  2. Combining texture and light.
    By noncopyable in forum OpenGL: GLSL
    Replies: 8
    Last Post: 10-11-2007, 09:23 AM
  3. A question about transparency ,deep test,color and light.
    By Mickey008 in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 11-26-2003, 01:50 AM
  4. Combining 2d and 3d?
    By DalTXColtsFan in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-18-2003, 06:26 AM
  5. OpenGL window transparency and texture transparency
    By ramalhais in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-15-2002, 09:37 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