GLUT Shading

Member
Posts: 40
Joined: 2008.10
Post: #1
Hey does anyone know what OpenGL calls I have to add to this code to make lights & shading work. (othing.c contains the C and GLUT libraries)
Code:
#include "othing.c"

int fullscreen=1;
float angle=0.0;
float thing=0.0;
float othing=-5.0;
int fthing=0;
int keys[255];
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };

void display(void) {
    myEvents();
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,othing);
    glRotatef(angle,0.0,1.0,0.0);
    glRotatef(angle,1.0,0.0,0.0);
    glRotatef(angle,0.0,0.0,1.0);
    
    glBegin(GL_QUADS);
    glNormal3f( 0.0f, 0.0f, 1.0f);
    glVertex3f(-1.0f, -1.0f,  1.0f);    
    glVertex3f( 1.0f, -1.0f,  1.0f);    
    glVertex3f( 1.0f,  1.0f,  1.0f);    
    glVertex3f(-1.0f,  1.0f,  1.0f);    

    glEnd();
    
    
    glPopMatrix();
    glutSwapBuffers();
    angle=angle+thing;
    
}

void otherkeys(unsigned char key, int x, int y){
    keys[key]=0;
}
    
void processNormalKeys(unsigned char key, int x, int y) {
    
    keys[key]=1;
}

void myEvents(void){
    if(keys[97])
    {
        thing=thing+0.001;
    }
    if(keys[115])
    {
        thing=thing-0.001;
    }
    if(keys[100])
    {
        othing=othing+0.01;
    }
    if(keys[102])
    {
        othing=othing-0.01;
    }
    if(keys[32])
    {
        if(fthing==0)
        {
            fthing=1;
        }else{
            fthing=0;
        }
    }
}
void reshape(int width, int height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);                        
    glLoadIdentity();                            
    
    
    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
    
    glMatrixMode(GL_MODELVIEW);                        
    glLoadIdentity();    
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
        
}

void idle(void)
{
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitWindowPosition(300,100);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(1000,800);
    
    glutCreateWindow("Super Ninja Deathmatch");
    if(fullscreen){glutFullScreen();}
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);
    glutKeyboardFunc(processNormalKeys);
    glutKeyboardUpFunc(otherkeys);
    glEnable(GL_DEPTH_TEST);
    
    
    glutMainLoop();
    return EXIT_SUCCESS;
}
Please excuse my bad variable naming and the like.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
Read some tutorials on lighting.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Deferred Shading wquist 0 2,620 Jul 20, 2011 07:42 PM
Last Post: wquist
  Irrlicht Gouraud/Smooth Shading merrill541 4 5,767 Feb 3, 2010 01:13 PM
Last Post: merrill541
  open gl shading language brtnrdr 8 5,374 Dec 30, 2004 02:15 AM
Last Post: OneSadCookie
  Anyone playing with the OpenGL Shading Laguage? NYGhost 7 4,971 Aug 4, 2004 01:23 PM
Last Post: OneSadCookie