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:: No Line Numbers


Fixed ViewPorts(?) by DELTRON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
 
// 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;
}