GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


Fixed ViewPorts(?) by DELTRON
// The issue you are having is with variables.  New key mapping is x,y,z for one pot, and X,Y,Z for the other pot -- Delt


#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL\glut.h>
#include <GL\gl.h>
#include <math.h>

static int WIN_H = 800; /* window height */
static int WIN_W = 800; /* window width */
static int WIN_POS_X = 200; /* window's x position */
static int WIN_POS_Y = 0; /* window's y position */

float xAngle;
float yAngle;

float xAngle2;
float yAngle2;


void drawTeapot() 
{
    glColor3f(150.0,200.0,100.0);
    glutWireTeapot(0.5);
    glFlush ();
}

void display()
{
    glClearColor(0.0,1.0,0.0,1.0);
    glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glViewport(0,0,WIN_W/2,WIN_H);
    gluPerspective(45.0,1.0* WIN_W/WIN_H,1.0,100.0);
    glTranslatef(0.0,0.0,-10.0);

    glRotatef(xAngle,1.0,0.0,0.0);
    glRotatef(yAngle,0.0,1.0,0.0);
    drawTeapot();


    glLoadIdentity();
    glOrtho(0.0,WIN_W,0.0,WIN_H,0.0,0.0);
    glMatrixMode(GL_MODELVIEW);
    glViewport(WIN_W/2,0,WIN_W/2,WIN_H);

    glRotatef(xAngle2,1.0,0.0,0.0);
    glRotatef(yAngle2,0.0,1.0,0.0);
    drawTeapot();
   
}

void keyboard (unsigned char key, int x, int y) {
    
if (key=='q' || key==27)
{
exit(1);
}

if(key == 'x')
{
    xAngle = 0.0;
    yAngle = 0.0;
    
    glutPostRedisplay();
}

if(key == 'y')
{
    
    xAngle = 90.0;
    yAngle = 0.0;
    
    glutPostRedisplay();
}
if(key == 'z')
{
    xAngle = 0.0;
    yAngle = 120.0;
    
    glutPostRedisplay();
    
}

if(key == 'X')
{
    xAngle2 = 0.0;
    yAngle2 = 0.0;
    
    glutPostRedisplay();
}

if(key == 'Y')
{
    
    xAngle2 = 90.0;
    yAngle2 = 0.0;
    
    glutPostRedisplay();
}
if(key == 'Z')
{
    xAngle2 = 0.0;
    yAngle2 = 120.0;
    
    glutPostRedisplay();
    
}

}

int main(int argc, char* argv[])
{    
    
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize(WIN_W,WIN_H);
   glutInitWindowPosition(WIN_POS_X, WIN_POS_Y);
   glutCreateWindow("OPENGL PROGRAM");
  
   glutDisplayFunc(display); 
   glutKeyboardFunc(keyboard);
   glutMainLoop();
   return 0;
}