Jump to content


OpenGL Lighting Problems


  • You cannot reply to this topic
12 replies to this topic

#1 Macerlask

    New Member

  • Members
  • PipPip
  • 14 posts

Posted 17 March 2006 - 03:31 PM

Ok, I'm using GLUT and the GLUT 3D objects and glQuadrics, there is a menu where u can select the object that you want, then you can rotate the objects with the mouse, translate it with the key pads or scale it with other keys.
Well, I am not very sure what the problem is, but when I rotate the objects some parts of the Front of the object is not rendered an you can se the inside of the object, other thing that I've noticed is that it looks like the light is moving with the object, if I´m not wrong the modelview matrix is transforming the position of the light, what I want is to leave the light in a static position, so that the modelview matrix doesn't transform the position of the light... :huh:


#include <GL/glut.h>

#include <stdio.h>

#include <math.h>


typedef enum {FIG1,FIG2,FIG3,FIG4,FIG5,FIG6,FIG7,FIG8,FIG9,FIG10,FIG11,FIG12, C1, C2, C3, C4, F1, F2, F3, F4} opcionesMenu;


int FIG=FIG1;

int F;


int FS=FIG1;


float alpha, beta;

int xs, ys;


GLfloat Tx=0;

GLfloat Ty=0;

GLfloat Sx=1;

GLfloat Sy=1;


// valores de las luces y coordenadas


GLfloat  LuzAmbiente[] = { 0.5f, 0.0f, 0.0f, 1.0f};

GLfloat  LuzDifusa[] =  { 1.0f, 0.5f, 0.5f, 1.0f };

GLfloat  LuzEspecular[] = { 1.0f, 1.0f, 1.0f, 1.0f};

GLfloat	 LuzPosicion[] = { 0.0f, 0.0f, 0.0f, 1.0f };


GLfloat gold_Ka[4] = { 0.24725f, 0.1995f, 0.0745f, 1.0f };

GLfloat gold_Kd[4] = { 0.75164f, 0.60648f, 0.22648f, 1.0f };

GLfloat gold_Ks[4] = { 0.628281f, 0.555802f, 0.366065f, 1.0f };

GLfloat gold_Ke    = 41.2f;

GLfloat silver_Ka[4]  = { 0.05f, 0.05f, 0.05f, 1.0f };

GLfloat silver_Kd[4]  = { 0.4f, 0.4f, 0.4f, 1.0f };

GLfloat silver_Ks[4]  = { 0.7f, 0.7f, 0.7f, 1.0f };

GLfloat silver_Ke     = 12.0f;



void onMenu(int opcion) 

{


	switch(opcion)

	{

		case FIG1:

					FIG=FIG1;

					break;

		case FIG2:

					FIG=FIG2;

					break;

		case FIG3:

					FIG=FIG3;

					break;

		case FIG4:

					FIG=FIG4;

					break;

		case FIG5:

					FIG=FIG5;

					break;

		case FIG6:

					FIG=FIG6;

					break;

		case FIG7:

					FIG=FIG7;

					break;

		case FIG8:

					FIG=FIG8;

					break;

		case FIG9:

					FIG=FIG9;

					break;

		case FIG10:

					FIG=FIG10;

					break;

		case FIG11:

					FIG=FIG11;

					break;

		case FIG12:

					FIG=FIG12;

					break;

	}

	glutPostRedisplay();

}


void onColor(int opcion) 

{


	switch(opcion)

	{

		case C1:

					glColor3f(1,0,0);

					break;

		case C2:

					glColor3f(0,1,0);

					break;

		case C3:

					glColor3f(0,0,1);

					break;

		case C4:

					glColor3f(1,1,1);

					break;

	}

	glutPostRedisplay();

}


void onFondo(int opcion) 

{


	switch(opcion)

	{

		case F1:

					glClearColor(0.3,0,0,0);

					break;

		case F2:

					glClearColor(0,0.3,0,0);

					break;

		case F3:

					glClearColor(0,0,0.3,0);

					break;

		case F4:

					glClearColor(0,0,0,0);

					break;

	}

	glutPostRedisplay();

}




void Keys(int key, int x, int y) {


	switch(key) {

		case GLUT_KEY_UP :

							Ty+=0.05;

							break;

		case GLUT_KEY_DOWN : 

							Ty-=0.05;

							break;

		case GLUT_KEY_RIGHT :

							Tx+=0.05;

						    break;

		case GLUT_KEY_LEFT : 

							Tx-=0.05;

						    break;

	}

}


void SKeys(unsigned char key, int x, int y) {


	switch((int)key) {

		case 45 :

							Sy-=0.05;

							Sx-=0.05;

						    break;

		case 43 : 

							Sy+=0.05;

							Sx+=0.05;

						    break;

	}

}


void onMouse(int button, int state, int x, int y) 

{

	if ( (button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN) ) {

		xs = x; ys = y;

		}

}


void onMotion(int x, int y) 

{

	alpha = (alpha + (y - ys));

	beta = (beta + (x - xs));

	xs = x; ys = y;

	glutPostRedisplay();

}


void DisplayX(void)

{

	

	

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


	glClearColor( 0.0, 0.0, 0.0, 0.0);

	glEnable(GL_DEPTH_TEST);

	glDisable(GL_CULL_FACE);

	glMatrixMode(GL_PROJECTION);

	glLoadIdentity();

	glOrtho(-1.0,1.0,-1.0,1.0,0, 100.0);

	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();

	glEnable(GL_LIGHTING);


}


void Menu(void)

{

	int menuFIG, menuPrincipal, menuC, menuF;

	

	menuFIG = glutCreateMenu(onMenu);


	glutAddMenuEntry("Torus", FIG1);

	glutAddMenuEntry("Esfera", FIG2);

	glutAddMenuEntry("Cono", FIG3);

	glutAddMenuEntry("Tetrahedro", FIG4);

	glutAddMenuEntry("Octahedro", FIG5);

	glutAddMenuEntry("Dodcahedro", FIG6);

	glutAddMenuEntry("Icosahedro", FIG7);

	glutAddMenuEntry("Tetera", FIG8);

	glutAddMenuEntry("Cilindro", FIG9);

	glutAddMenuEntry("Disco", FIG10);

	glutAddMenuEntry("Disco parcial", FIG11);

	glutAddMenuEntry("Esfera", FIG12);

	

	menuC = glutCreateMenu(onColor);

	glutAddMenuEntry("Rojo", C1);

	glutAddMenuEntry("Verde", C2);

	glutAddMenuEntry("Azul", C3);

	glutAddMenuEntry("Blanco", C4);


	menuF = glutCreateMenu(onFondo);

	glutAddMenuEntry("Rojo", F1);

	glutAddMenuEntry("Verde", F2);

	glutAddMenuEntry("Azul", F3);

	glutAddMenuEntry("Negro", F4);


	menuPrincipal = glutCreateMenu(onMenu);

	glutAddSubMenu("Color Figura", menuC);

	glutAddSubMenu("Color Fondo", menuF);

	glutAddSubMenu("Figura", menuFIG);

	


	glutAttachMenu(GLUT_RIGHT_BUTTON);

}


void idle(void)

{

	GLUquadricObj *MyQuadric;


	glLightfv(GL_LIGHT0, GL_AMBIENT, LuzAmbiente);

	glLightfv(GL_LIGHT0, GL_DIFFUSE, LuzDifusa);

	glLightfv(GL_LIGHT0, GL_SPECULAR, LuzEspecular);

	glLightfv(GL_LIGHT0, GL_POSITION, LuzPosicion);

	glEnable(GL_LIGHT0);


	glMaterialfv(GL_FRONT, GL_AMBIENT,  gold_Ka);

    glMaterialfv(GL_FRONT, GL_DIFFUSE,  gold_Kd);

    glMaterialfv(GL_FRONT, GL_SPECULAR, gold_Ks);

    glMaterialf(GL_FRONT, GL_SHININESS, gold_Ke);

    glMaterialfv(GL_BACK, GL_AMBIENT,  silver_Ka);

    glMaterialfv(GL_BACK, GL_DIFFUSE,  silver_Kd);

    glMaterialfv(GL_BACK, GL_SPECULAR, silver_Ks);

    glMaterialf(GL_BACK, GL_SHININESS, silver_Ke);


	if(FS!=FIG)

	{

		FS=FIG;

		Tx=0;

		Ty=0;

		Sx=1;

		Sy=1;

		ys=xs=0;

		alpha=beta=0;

	}


	glTranslatef(Tx,Ty,0);

	glScalef(Sx,Sy,0);

	glRotatef(alpha, 1.0f, 0.0f, 0.0f);

	glRotatef(beta, 0.0f, 1.0f, 0.0f);


	MyQuadric=gluNewQuadric();

	gluQuadricDrawStyle(MyQuadric, GLU_LINE);


	switch(FIG)

	{

		case FIG1: glutSolidTorus  ( 0.3 , 0.5 , 25 , 50);

				   break;

		case FIG2: glutSolidSphere  ( 0.7 , 30 , 30 );

				   break;

		case FIG3: glutSolidCone  ( 0.7, 1 , 25, 30 ); ;

				   break;

		case FIG4: glutWireTetrahedron ();

				   break;

		case FIG5: glutWireOctahedron ();

				   break;

		case FIG6: glutWireDodecahedron ();

				   break;

		case FIG7: glutWireIcosahedron  (); ;

				   break;

		case FIG8: glutSolidTeapot(0.5);

				   break;

		case FIG9: gluCylinder(MyQuadric, 0.3, 0.3, 0.9, 20, 10 );  

				   break;

		case FIG10: gluDisk(MyQuadric, 0.3, 0.5, 20, 5); 

				   break;

		case FIG11: gluPartialDisk(MyQuadric, 0.3, 0.5, 20, 5, 0, 90); 

				   break;

		case FIG12: gluSphere(MyQuadric, 0.7 , 30 , 30);

				   break;

	}


	glFlush();

	glutSwapBuffers();

}


void main(int argc, char **argv)

{

	glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);

	glutInitWindowSize(400,400);

	glutInitWindowPosition(300,200);

	glutCreateWindow("Transformaciones 2D");

	glClearColor (0.0, 0.0, 0.0, 0.0);

	glutDisplayFunc(DisplayX);

	glutIdleFunc(idle);

	glutMouseFunc(onMouse);

	glutMotionFunc(onMotion);

	glutSpecialFunc(Keys);

	glutKeyboardFunc(SKeys);

	Menu();

	

	glutMainLoop();

}



#2 bignobody

    Valued Member

  • Members
  • PipPipPip
  • 155 posts

Posted 17 March 2006 - 04:01 PM

I'm not an OpenGL guy myself (though there are quite a few that hang out here) but the front of the object not being rendered is probably due to it being clipped by the front clip plane. I'm not sure how this is set in OpenGL, but you can test if this is the case by moving the object further away from the camera.
-bignobody
notsoftgames.com - Creator of Shlongg!

#3 Macerlask

    New Member

  • Members
  • PipPip
  • 14 posts

Posted 17 March 2006 - 04:18 PM

Yea actually I've, at first time i thought the same, but it looks like that is not the problem...

#4 Apocalypse

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 17 March 2006 - 04:51 PM

You did some strange things there...
Everything that draws must be placed in the Render function, not in the idle. Maybe your problem is that your rendering actually takes place both in the idle function (most of it) and in the render function; and you can't be sure when idle is called, relatively to the render. Try to put all the code from the idle function to the render function.

Hope this helps;
Apocalypse, the End of the World.

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 17 March 2006 - 06:38 PM

The light position is always transformed by the modelview matrix, and its location is stored in eye space so it will remain at a constant location with respect to the camera. You are currently setting the light position every frame, which is the usual way to make a light that is fixed in world space. If you want to set the light's position in eye space, then do so once, during the setup, with an identity modelview matrix, and then don't update it during the rendering.
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 Macerlask

    New Member

  • Members
  • PipPip
  • 14 posts

Posted 18 March 2006 - 01:39 AM

Quote

then do so once, during the setup, with an identity modelview matrix, and then don't update it during the rendering.

I think, I understand what are you trying to say me and the red book says something similar, but... :blush: How should I do that?

Could you write a small example code, where u set the lights up?


Thanks for the help

#7 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 18 March 2006 - 01:42 AM

void Init ()
{
    // blah
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glLightfv(GL_LIGHT0, GL_POSITION, thePosition);
}

reedbeta.com - developer blog, OpenGL demos, and other projects

#8 Macerlask

    New Member

  • Members
  • PipPip
  • 14 posts

Posted 18 March 2006 - 02:09 AM

:wacko: Well, I did that and it still not working... :wallbash:

#9 Macerlask

    New Member

  • Members
  • PipPip
  • 14 posts

Posted 18 March 2006 - 02:37 AM

Here is the code modified :surrender

#include <GL/glut.h>

#include <stdio.h>

#include <math.h>


typedef enum {FIG1,FIG2,FIG3,FIG4,FIG5,FIG6,FIG7,FIG8,FIG9,FIG10,FIG11,FIG12, C1, C2, C3, C4, F1, F2, F3, F4} opcionesMenu;


int FIG=FIG1;

int F;


int FS=FIG1;


float alpha, beta;

int xs, ys;


GLfloat Tx=0;

GLfloat Ty=0;

GLfloat Sx=1;

GLfloat Sy=1;


// valores de las luces y coordenadas


GLfloat  LuzAmbiente[] = { 0.5f, 0.0f, -1.0f, 1.0f};

GLfloat  LuzDifusa[] =  { 1.0f, 1.f, 1.f, 1.0f };

GLfloat  LuzEspecular[] = { 1.0f, 1.0f, 1.0f, 1.0f};

GLfloat	 LuzPosicion[] = { 0.0f, 0.0f, 0.0f, 1.0f };


GLfloat gold_Ka[4] = { 0.24725f, 0.1995f, 0.0745f, 1.0f };

GLfloat gold_Kd[4] = { 0.75164f, 0.60648f, 0.22648f, 1.0f };

GLfloat gold_Ks[4] = { 0.628281f, 0.555802f, 0.366065f, 1.0f };

GLfloat gold_Ke    = 41.2f;

GLfloat silver_Ka[4]  = { 0.05f, 0.05f, 0.05f, 1.0f };

GLfloat silver_Kd[4]  = { 0.4f, 0.4f, 0.4f, 1.0f };

GLfloat silver_Ks[4]  = { 0.7f, 0.7f, 0.7f, 1.0f };

GLfloat silver_Ke     = 12.0f;



void onMenu(int opcion) 

{


	switch(opcion)

	{

		case FIG1:

					FIG=FIG1;

					break;

		case FIG2:

					FIG=FIG2;

					break;

		case FIG3:

					FIG=FIG3;

					break;

		case FIG4:

					FIG=FIG4;

					break;

		case FIG5:

					FIG=FIG5;

					break;

		case FIG6:

					FIG=FIG6;

					break;

		case FIG7:

					FIG=FIG7;

					break;

		case FIG8:

					FIG=FIG8;

					break;

		case FIG9:

					FIG=FIG9;

					break;

		case FIG10:

					FIG=FIG10;

					break;

		case FIG11:

					FIG=FIG11;

					break;

		case FIG12:

					FIG=FIG12;

					break;

	}

	glutPostRedisplay();

}


void onColor(int opcion) 

{


	switch(opcion)

	{

		case C1:

					glColor3f(1,0,0);

					break;

		case C2:

					glColor3f(0,1,0);

					break;

		case C3:

					glColor3f(0,0,1);

					break;

		case C4:

					glColor3f(1,1,1);

					break;

	}

	glutPostRedisplay();

}


void onFondo(int opcion) 

{


	switch(opcion)

	{

		case F1:

					glClearColor(0.3,0,0,0);

					break;

		case F2:

					glClearColor(0,0.3,0,0);

					break;

		case F3:

					glClearColor(0,0,0.3,0);

					break;

		case F4:

					glClearColor(0,0,0,0);

					break;

	}

	glutPostRedisplay();

}




void Keys(int key, int x, int y) {


	switch(key) {

		case GLUT_KEY_UP :

							Ty+=0.05;

							break;

		case GLUT_KEY_DOWN : 

							Ty-=0.05;

							break;

		case GLUT_KEY_RIGHT :

							Tx+=0.05;

						    break;

		case GLUT_KEY_LEFT : 

							Tx-=0.05;

						    break;

	}

}


void SKeys(unsigned char key, int x, int y) {


	switch((int)key) {

		case 45 :

							Sy-=0.05;

							Sx-=0.05;

						    break;

		case 43 : 

							Sy+=0.05;

							Sx+=0.05;

						    break;

	}

}


void onMouse(int button, int state, int x, int y) 

{

	if ( (button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN) ) {

		xs = x; ys = y;

		}

}


void onMotion(int x, int y) 

{

	alpha = (alpha + (y - ys));

	beta = (beta + (x - xs));

	xs = x; ys = y;

	glutPostRedisplay();

}


void DisplayX(void)

{

    GLUquadricObj *MyQuadric;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    glEnable(GL_LIGHT0);


    glMaterialfv(GL_FRONT, GL_AMBIENT,  gold_Ka);

    glMaterialfv(GL_FRONT, GL_DIFFUSE,  gold_Kd);

    glMaterialfv(GL_FRONT, GL_SPECULAR, gold_Ks);

    glMaterialf(GL_FRONT, GL_SHININESS, gold_Ke);

    glMaterialfv(GL_BACK, GL_AMBIENT,  silver_Ka);

    glMaterialfv(GL_BACK, GL_DIFFUSE,  silver_Kd);

    glMaterialfv(GL_BACK, GL_SPECULAR, silver_Ks);

    glMaterialf(GL_BACK, GL_SHININESS, silver_Ke);


	if(FS!=FIG)

	{

		FS=FIG;

		Tx=0;

		Ty=0;

		Sx=1;

		Sy=1;

		ys=xs=0;

		alpha=beta=0;

	}


	glPushMatrix();


	glTranslatef(Tx,Ty,0);

	glScalef(Sx,Sy,0);

	glRotatef(alpha, 1.0f, 0.0f, 0.0f);

	glRotatef(beta, 0.0f, 1.0f, 0.0f);


	MyQuadric=gluNewQuadric();

	gluQuadricDrawStyle(MyQuadric, GLU_FILL);


	switch(FIG)

	{

		case FIG1: glutSolidTorus  ( 0.3 , 0.5 , 25 , 50);

				   break;

		case FIG2: glutSolidSphere  ( 0.7 , 30 , 30 );

				   break;

		case FIG3: glutSolidCone  ( 0.7, 1 , 25, 30 ); ;

				   break;

		case FIG4: glutSolidTetrahedron ();

				   break;

		case FIG5: glutSolidOctahedron ();

				   break;

		case FIG6: glutSolidDodecahedron ();

				   break;

		case FIG7: glutSolidIcosahedron  (); ;

				   break;

		case FIG8: glutSolidTeapot(0.5);

				   break;

		case FIG9: gluCylinder(MyQuadric, 0.3, 0.3, 0.9, 20, 10 );  

				   break;

		case FIG10: gluDisk(MyQuadric, 0.3, 0.5, 20, 5); 

				   break;

		case FIG11: gluPartialDisk(MyQuadric, 0.3, 0.5, 20, 5, 0, 90); 

				   break;

		case FIG12: gluSphere(MyQuadric, 0.7 , 30 , 30);

				   break;

	}


	glPopMatrix();


	glFlush();

	glutSwapBuffers();

}


void Setup(void)

{

	glEnable(GL_DEPTH_TEST);

	glDisable(GL_CULL_FACE);

	glMatrixMode(GL_PROJECTION);

	glLoadIdentity();

	glOrtho(-1.0,1.0,-1.0,1.0,0, 100.0);

	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();

	glLightfv(GL_LIGHT0, GL_POSITION, LuzPosicion);

	glLightfv(GL_LIGHT0, GL_POSITION, LuzPosicion);

	glLightfv(GL_LIGHT0, GL_AMBIENT, LuzAmbiente);

	glLightfv(GL_LIGHT0, GL_DIFFUSE, LuzDifusa);

	glLightfv(GL_LIGHT0, GL_SPECULAR, LuzEspecular);

	glEnable(GL_LIGHTING);


	

}


void Menu(void)

{

	int menuFIG, menuPrincipal, menuC, menuF;

	

	menuFIG = glutCreateMenu(onMenu);


	glutAddMenuEntry("Torus", FIG1);

	glutAddMenuEntry("Esfera", FIG2);

	glutAddMenuEntry("Cono", FIG3);

	glutAddMenuEntry("Tetrahedro", FIG4);

	glutAddMenuEntry("Octahedro", FIG5);

	glutAddMenuEntry("Dodcahedro", FIG6);

	glutAddMenuEntry("Icosahedro", FIG7);

	glutAddMenuEntry("Tetera", FIG8);

	glutAddMenuEntry("Cilindro", FIG9);

	glutAddMenuEntry("Disco", FIG10);

	glutAddMenuEntry("Disco parcial", FIG11);

	glutAddMenuEntry("Esfera", FIG12);

	

	menuC = glutCreateMenu(onColor);

	glutAddMenuEntry("Rojo", C1);

	glutAddMenuEntry("Verde", C2);

	glutAddMenuEntry("Azul", C3);

	glutAddMenuEntry("Blanco", C4);


	menuF = glutCreateMenu(onFondo);

	glutAddMenuEntry("Rojo", F1);

	glutAddMenuEntry("Verde", F2);

	glutAddMenuEntry("Azul", F3);

	glutAddMenuEntry("Negro", F4);


	menuPrincipal = glutCreateMenu(onMenu);

	glutAddSubMenu("Color Figura", menuC);

	glutAddSubMenu("Color Fondo", menuF);

	glutAddSubMenu("Figura", menuFIG);

	


	glutAttachMenu(GLUT_RIGHT_BUTTON);

}


void main(int argc, char **argv)

{

	

	glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);

	glutInitWindowSize(400,400);

	glutInitWindowPosition(300,200);

	glutCreateWindow("Transformaciones 2D");

             glClearColor (0.0, 0.0, 0.0, 0.0);

	Setup();

	glutDisplayFunc(DisplayX);

	glutIdleFunc(DisplayX);

	glutMouseFunc(onMouse);

	glutMotionFunc(onMotion);

	glutSpecialFunc(Keys);

	glutKeyboardFunc(SKeys);

	Menu();

	

	glutMainLoop();

}


#10 Mjolnir

    Member

  • Members
  • PipPip
  • 42 posts

Posted 18 March 2006 - 11:02 AM

And here are a couple of fixes...

void DisplayX(void)
{
    GLUquadricObj *MyQuadric;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // added this 3 lines
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);

    glMaterialfv(GL_FRONT, GL_AMBIENT,  gold_Ka);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,  gold_Kd);
    glMaterialfv(GL_FRONT, GL_SPECULAR, gold_Ks);
    glMaterialf(GL_FRONT, GL_SHININESS, gold_Ke);
    glMaterialfv(GL_BACK, GL_AMBIENT,  silver_Ka);
    glMaterialfv(GL_BACK, GL_DIFFUSE,  silver_Kd);
    glMaterialfv(GL_BACK, GL_SPECULAR, silver_Ks);
    glMaterialf(GL_BACK, GL_SHININESS, silver_Ke);

	if(FS!=FIG)
	{
		FS=FIG;
		Tx=0;
		Ty=0;
		Sx=1;
		Sy=1;
		ys=xs=0;
		alpha=beta=0;
	}

	glPushMatrix();

	glTranslatef(Tx,Ty,0);
	// changed z = 0 to z = 1
	glScalef(Sx,Sy,1);
	glRotatef(alpha, 1.0f, 0.0f, 0.0f);
	glRotatef(beta, 0.0f, 1.0f, 0.0f);

	MyQuadric=gluNewQuadric();
	gluQuadricDrawStyle(MyQuadric, GLU_FILL);

	switch(FIG)
	{
		case FIG1: glutSolidTorus  ( 0.3 , 0.5 , 25 , 50);
				   break;
		case FIG2: glutSolidSphere  ( 0.7 , 30 , 30 );
				   break;
		case FIG3: glutSolidCone  ( 0.7, 1 , 25, 30 ); ;
				   break;
		case FIG4: glutSolidTetrahedron ();
				   break;
		case FIG5: glutSolidOctahedron ();
				   break;
		case FIG6: glutSolidDodecahedron ();
				   break;
		case FIG7: glutSolidIcosahedron  (); ;
				   break;
		case FIG8: glutSolidTeapot(0.5);
				   break;
		case FIG9: gluCylinder(MyQuadric, 0.3, 0.3, 0.9, 20, 10 );  
				   break;
		case FIG10: gluDisk(MyQuadric, 0.3, 0.5, 20, 5); 
				   break;
		case FIG11: gluPartialDisk(MyQuadric, 0.3, 0.5, 20, 5, 0, 90); 
				   break;
		case FIG12: gluSphere(MyQuadric, 0.7 , 30 , 30);
				   break;
	}

	glPopMatrix();

	glFlush();
	glutSwapBuffers();
}

void Setup(void)
{
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-1.0,1.0,-1.0,1.0,0, 100.0);
	
	// changed
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_POSITION, LuzPosicion);
	glLightfv(GL_LIGHT0, GL_AMBIENT, LuzAmbiente);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, LuzDifusa);
	glLightfv(GL_LIGHT0, GL_SPECULAR, LuzEspecular);	
}


#11 Macerlask

    New Member

  • Members
  • PipPip
  • 14 posts

Posted 18 March 2006 - 02:54 PM

It works :w00t:

Thanks for your help MjoInir and Reedbeta ...

:lol:

#12 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 893 posts

Posted 18 March 2006 - 05:22 PM

Screenie?

Or could you even share the code with us?

#13 mysticman

    Member

  • Members
  • PipPip
  • 95 posts

Posted 18 March 2006 - 10:03 PM

geon said:

Screenie?

Or could you even share the code with us?

yeah!:happy:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users