Thread: OpenGL graphics

  1. #1
    Registered User
    Join Date
    Mar 2007

    OpenGL graphics


    I'm having trouble getting around what everything means in the lighting and section of OpenGL. I have managed to get lighting working, but whatever i try for shading doesn't work. I've been working of tutorials but can't make much sense of it. If anybody could help me understand whats going on and how to get shading working would be great. Ive got comments on my code which is as far as i understand.

    void glutInit(int argc, char ** argv) 
      	// Setup the basic GLUT stuff
    	glutInit(&argc, argv); 						// initialises environment
      	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 	// uses a double buffer - colour mode - 
      	// Create the window
    	glutInitWindowSize(200, 200); 					// creates the window size
      	glutInitWindowPosition(100, 150);  				// position of the window on the screen
      	glutCreateWindow("3D Draughts");
    	// Register the event callback functions
    	glutDisplayFunc(Display); 					// called everytime it needs to refresh the display
    	glutIdleFunc(idle); 						// called when it isnt doing anything
      	glutKeyboardFunc(KeyboardHandler);         			// picks up keyboard strokes
    	glutMouseFunc(processMouse);					// mouse movement and clicks
    	glutReshapeFunc(Reshape); 					// called everytime it needs to reshape something
    	glEnable(GL_DEPTH_TEST);					// Enabling depth test
    	glEnable(GL_COLOR_MATERIAL);					// Allows colored materials to be affected by the light
      	glEnable(GL_LIGHTING);		// Enable lighting
    	glEnable(GL_LIGHT0);						// Enable 1st light, possible 8 - max
    	glLightfv(GL_LIGHT0, GL_POSITION, LightPos);			// set light position
      	glLightfv(GL_LIGHT0, GL_DIFFUSE, LightColor);			// setting diffuse colour
      	glLightfv(GL_LIGHT0, GL_SPECULAR, LightColor);			// setting specular colour
    									// At this point, control is relinquished to the GLUT event handler.
      	glutMainLoop();   						// Control is returned as events occur, via the callback functions.

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Where circles begin.
    What exactly do you mean by "shading"? Shadows? Or just the dark parts that face away from the light?

    If the latter, you might want to try setting the ambient lighting term, like this:
    float lightAmbient[4] = {0.1f, 0.1f, 0.1f, 1.0f};
    glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  3. #3

    Join Date
    May 2005
    You need to specify a normal at each vertex, if I understand what you are asking for. I believe you mean Goraud shading. Note that this only produces reasonably good results for densely tesselated models (each polygon is small), because it interpolates the value of the normal across the face (meaning as you get towards the center of a large polygon you will notice the effects of the averaged normals).

    If you simply meant for coloring, you need to enable smooth shading and supply a different color per vertex.

    Also, what the hell is a 'draught?'
    I'm not immature, I'm refined in the opposite direction.

  4. #4
    Registered User
    Join Date
    Mar 2007
    lol, checkers?? we call it draughts... well 'they'..... i just want simple shadows so you can tell its 3D, from far, atm sometimes it looks 2.

  5. #5
    Registered User
    Join Date
    Mar 2007
    I tried what psychopath suggested, but no luck. I didnt make up my shapes of polygons, i'm not on that level, i simply stuck together 2D shapes to make 3D shapes. I just want simple shadows now, so it adds to the realism. My light is shining from the top, and when you move the camera through it to the bottom side, it is dark. Maybe my positionbing of my light is incorrent??

    const GLfloat LightPos[] = { 0.0, 0.0, 1.0, 0.0 };
    const GLfloat LightColor[] = {  1.0f, 1.0f,1.0f, 1.0f };

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    There is no integrated support for shadows in OpenGL. You need to do the calculations yourself.

    For something simple like checkers, you could just render a simple dark circle under each piece offset by a constant factor.

  7. #7
    Registered User
    Join Date
    Mar 2007
    i see, what about shading on the peices ??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  2. Adding 2D graphics in OpenGL
    By Da-Nuka in forum Game Programming
    Replies: 7
    Last Post: 04-05-2005, 02:26 PM
  3. OpenGL graphics
    By Da-Nuka in forum Game Programming
    Replies: 9
    Last Post: 03-31-2005, 09:52 AM
  4. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM