spheres with common part

I give you the above source code.With this code i draw two sheres(a red and a green).
I want half of the red sphere to be inside
the green sphere and half of the green sphere to be inside the red sphere.The two parts i want to be invisible.In other words i don’t want the common part to darken or to chenge colour.
What changes should I make???

i don’t want to be like this
(imagine that [] is a sphere)
[] []

of course if what i say does not exist can someone show me a technique how to cut the one sphere in tow half-spheres. like cutting an orange in the middle.

the code is:

#include <math.h> // - for mathematic functions
#include <stdlib.h> // - for the exit condition
#include <windows.h> // - Windows API and system calls
#include <stdio.h> // - Just for some ASCII messages
#include <gl/gl.h> // - The OpenGL API
#include <gl/glaux.h> // - A windows library extension API
#include <gl/glut.h> // - An interface and windows
// management library

//-------- Functions --------------------------------

void keyboard( unsigned char key, int x, int y ) ;//for the esc button
void Render(); // The function responsible for drawing everything in the
// OpenGL context associated to a window.

void Resize(int w, int h); // Handle the window size changes and define the world coordinate
// system and projection type

void Setup(); // Set up the OpenGL state machine and create a light source

////////////////// State Variables ////////////////////////

BOOL done=FALSE;
bool keys[256]; // Array Used For The Keyboard Routine
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

///////////////// Main Program ///////////////////////////

void main(int argc, char* argv[])
{

// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL,“Would You Like To Run In Fullscreen Mode?”, “Start FullScreen?”,MB_YESNO|MB_ICONQUESTION)==IDNO)
fullscreen=FALSE; // Windowed Mode

if(fullscreen==FALSE)
{
glutInit(&argc, argv); // initialize GLUT library state
glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE); // Set up the display using the GLUT functions to
// get rid of the window setup details:
// - Use true RGB colour mode ( and transparency )
// - Enable double buffering for faster window update
// - Allocate a Depth-Buffer in the system memory or
// in the video memory if 3D acceleration available

glutInitWindowSize(480,480); // Define the main window size and initial position
glutInitWindowPosition(50,50); // ( upper left corner, boundaries included )

// Create and label the main window
glutCreateWindow(“Pavlopoulos_Georgios-018200000146-PENGUIN”);

// Configure various properties of the OpenGL rendering context
Setup();

// Callbacks for the GL and GLUT events:

glutDisplayFunc(Render); // The rendering function
glutReshapeFunc(Resize);

glutIdleFunc(Render);

glutMainLoop(); //Enter main event handling loop
}

else if (fullscreen==TRUE)
{
glutInit(&argc, argv) ;

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) ;

glutGameModeString(“1024x768:32@60”) ;

while(!done) // Loop That Runs While done=FALSE
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()

if (keys[VK_ESCAPE]) // Was ESC Pressed?
done=TRUE; // ESC Signalled A Quit

else
{
if (glutGameModeGet(GLUT_GAME_MODE_WIDTH) != -1) // if the width is different to -1

{

glutEnterGameMode() ; // enter full screen mode
glutKeyboardFunc(keyboard);
glutDisplayFunc(Render) ;
glutReshapeFunc(Resize) ;
glutIdleFunc(Render) ;

}

else // print out that this mode is not available

printf("The current mode is not supported in this system
") ;

glutMainLoop();
}
glutSwapBuffers();
}//while
}
}//end of main

void keyboard( unsigned char key, int x, int y )
{
switch ( key )
case 27:
exit( 0 );
}

void Render(){
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CCW);

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0,-100.0 );

//-------------------------------------------green sphere
glPushMatrix();
glTranslatef( 0,0,0);
glScalef(1.36,1.36,1.36);
glColor4f(0.3,0.7,0.3,1.0);
glutSolidSphere(8,35,22);
glPopMatrix();

//-------------------------------------------red sphere
glPushMatrix();
glTranslatef( 10,0,0);
glScalef(1.36,1.36,1.36);
glColor4f(0.7,0.3,0.3,1.0);
glutSolidSphere(8,35,22);
glPopMatrix();

glutSwapBuffers();
}

void Resize(int w, int h)
{

// define the visible area of the window ( in pixels )
if (h==0) h=1;
glViewport(0,0,w,h);

// Setup viewing volume
// glOrtho (-50.0f, 50.0f, -50.0f, 50.0f,100.0f,-100.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-50.0f,50.0f,-50.0,50.0f,-1500.0f,-1500.0f);

// L R B T N F
gluPerspective(60.0, w/h, 1.0, 500.0 );

}

//-----------------------------------------------------------

void Setup()
{
bool bDepth=FALSE;

glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glEnable( GL_CULL_FACE );
glEnable( GL_LIGHTING );
glShadeModel( GL_SMOOTH );

if(bDepth)
glEnable(GL_DEPTH_TEST);
else
glDisable(GL_DEPTH_TEST);

//Set up light source
GLfloat ambientLight[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat diffuseLight[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat lightPos[] = { -30.0, 20.0, 170.0, 1.0 };

glLightfv( GL_LIGHT0, GL_AMBIENT, ambientLight );
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseLight );
glLightfv( GL_LIGHT0, GL_POSITION,lightPos );
glEnable( GL_LIGHT0);

// polygon rendering mode and material properties
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

// Blue background
glClearColor(0.0f,0.0f,1.0f,1.0f);

}

If you don’t want the two colors to blend through each other, try glDisable(GL_BLEND) before drawing your spheres.

Now if you want one half of the sphere to be one color and the other half another. You can do the following:

  1. build the sphere from primitives, building one half green the other red.

  2. use a texture map of with red on half of the texture and green on the other half.

Originally posted by pavlov123:
[b]I give you the above source code.With this code i draw two sheres(a red and a green).
I want half of the red sphere to be inside
the green sphere and half of the green sphere to be inside the red sphere.The two parts i want to be invisible.In other words i don’t want the common part to darken or to chenge colour.
What changes should I make???

i don’t want to be like this
(imagine that is a sphere)

of course if what i say does not exist can someone show me a technique how to cut the one sphere in tow half-spheres. like cutting an orange in the middle.

the code is:

#include <math.h> // - for mathematic functions
#include <stdlib.h> // - for the exit condition
#include <windows.h> // - Windows API and system calls
#include <stdio.h> // - Just for some ASCII messages
#include <gl/gl.h> // - The OpenGL API
#include <gl/glaux.h> // - A windows library extension API
#include <gl/glut.h> // - An interface and windows
// management library

//-------- Functions [/b]