CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2001
    Location
    lake of fire and brimstone
    Posts
    1,628

    gluSphere transparent background

    Attachment 33627

    Hi all,

    for my program I want to try something new, I would like to draw a transparent sphere with a smaller non transparent one inside, as illustrated. Any idea how to do this?

    All I can do, is some blending when the sphere is behind an object, but I can't make it really blend when it is in the foreground. Below is the code I currently use for drawing the sphere.

    Code:
     // Draw a sphere at the position of the node
    
     GLfloat ambient1[]	 = {0.5f, 0.5f,0.5f,1.0f};
     GLfloat ambient2[]	 = {0.2f, 0.2f,0.2f,1.0f};
     GLfloat diffuse[]	 = {0.7f, 0.7f,0.7f,1.0f};
     GLfloat position1[] = {0.0f,-1.0f,0.0f,0.0f};
     GLfloat position2[] = {0.0f, 1.0f,0.0f,0.0f};
     GLfloat spec[]		 = {1.0f, 1.0f,1.0f,1.0f};
     GLfloat specma[]	 = {1.0f, 1.0f,1.0f,1.0f};
    
     glShadeModel(GL_SMOOTH);						// Smooth rendering
     glFrontFace(GL_CCW);							// Counter clock-wise polygons face out
    
     glEnable(GL_DEPTH_TEST);						// Hidden surface removal
     glEnable(GL_LIGHTING);							// Enable lighting
    
     glEnable(GL_POLYGON_OFFSET_FILL);				// Correction for small errors
     glPolygonOffset(0.5, 2.0);
    
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient1);
     glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1);
     glLightfv(GL_LIGHT0,GL_POSITION,position1);	// Setup and enable light 0
     glLightfv(GL_LIGHT0,GL_AMBIENT,ambient2);
     glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse);
     glLightfv(GL_LIGHT0,GL_SPECULAR,spec);
     glEnable(GL_LIGHT0);
     glLightfv(GL_LIGHT1,GL_POSITION,position2);	// Setup and enable light 1
     glLightfv(GL_LIGHT1,GL_AMBIENT,ambient2);
     glLightfv(GL_LIGHT1,GL_DIFFUSE,diffuse);
     glLightfv(GL_LIGHT1,GL_SPECULAR,spec);
     glEnable(GL_LIGHT1);
    
     glEnable(GL_COLOR_MATERIAL);					// Set Material properties to follow glColor values
     glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
     glMaterialfv(GL_FRONT,GL_SPECULAR,specma);
     glMateriali(GL_FRONT,GL_SHININESS,128);
    
     glColor4d(0,0,1,0.150);
    
     GLUquadricObj *quadric=gluNewQuadric();
    
     gluQuadricNormals(quadric, GLU_SMOOTH);
    
     glTranslated( P.x, P.y, P.z );
    
     double radius = 0.002;
     
     gluSphere(quadric,radius,50,50);
    
     glEnable( GL_BLEND );
     glDisable(GL_DEPTH_TEST);
     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    
     gluSphere(quadric,radius,50,50);
    
     glEnable(GL_DEPTH_TEST);
    
     glTranslated(-P.x,-P.y,-P.z );
    
     gluDeleteQuadric(quadric);
    
     //// restore rendering context //
    
     glDisable(GL_POLYGON_OFFSET_FILL);
     glDisable(GL_COLOR_MATERIAL);
     glDisable(GL_LIGHTING);
     glDisable(GL_LIGHT1);
     glDisable(GL_LIGHT0);
     glDisable(GL_BLEND);
    Attached Images Attached Images  
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured