-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
137 lines (116 loc) · 4.33 KB
/
main.cpp
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
136
137
/******************************************************************************/
/* This is the program skeleton for homework 2 in CSE167 by Ravi Ramamoorthi */
/* Extends HW 1 to deal with shading, more transforms and multiple objects */
/******************************************************************************/
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <deque>
#include <stack>
#include <FreeImage.h>
using namespace std;
// Main variables in the program.
#define MAINPROGRAM
#include "Transform.h"
#include "variables.h"
#include "readfile.h" // prototypes for readfile.cpp
#include "display.h"
bool allowGrader = false;
// Reshapes the window
void reshape(int width, int height){
w = width;
h = height;
//glViewport(0, 0, w, h);
float aspect = (float) w / (float) h, zNear = 0.1, zFar = 99.0 ;
// I am changing the projection matrix to fit with the new window aspect ratio
projection = Transform::perspective(fovy,aspect,zNear,zFar) ;
}
void saveScreenshot(string fname) {
int pix = w * h;
BYTE *pixels = new BYTE[3*pix];
// glReadBuffer(GL_FRONT);
// glReadPixels(0,0,w,h,GL_BGR,GL_UNSIGNED_BYTE, pixels);
FIBITMAP *img = FreeImage_ConvertFromRawBits(pixels, w, h, w * 3, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
std::cout << "Saving screenshot: " << fname << "\n";
FreeImage_Save(FIF_PNG, img, fname.c_str(), 0);
delete[] pixels;
}
void printHelp() {
std::cout << "\npress 'h' to print this message again.\n"
<< "press '+' or '-' to change the amount of rotation that\noccurs with each arrow press.\n"
<< "press 'i' to run image grader test cases\n"
<< "press 'g' to switch between using glm::lookAt and glm::Perspective or your own LookAt.\n"
<< "press 'r' to reset the transformations.\n"
<< "press 'v' 't' 's' to do view [default], translate, scale.\n"
<< "press ESC to quit.\n\n" ;
}
/*
void init() {
// Initialize shaders
vertexshader = initshaders(GL_VERTEX_SHADER, "shaders/light.vert.glsl") ;
fragmentshader = initshaders(GL_FRAGMENT_SHADER, "shaders/light.frag.glsl") ;
shaderprogram = initprogram(vertexshader, fragmentshader) ;
// Get locations of all uniform variables.
enablelighting = glGetUniformLocation(shaderprogram,"enablelighting") ;
lightpos = glGetUniformLocation(shaderprogram,"lightposn") ;
lightcol = glGetUniformLocation(shaderprogram,"lightcolor") ;
numusedcol = glGetUniformLocation(shaderprogram,"numused") ;
ambientcol = glGetUniformLocation(shaderprogram,"ambient") ;
diffusecol = glGetUniformLocation(shaderprogram,"diffuse") ;
specularcol = glGetUniformLocation(shaderprogram,"specular") ;
emissioncol = glGetUniformLocation(shaderprogram,"emission") ;
shininesscol = glGetUniformLocation(shaderprogram,"shininess") ;
projectionPos = glGetUniformLocation(shaderprogram, "projection");
modelviewPos = glGetUniformLocation(shaderprogram, "modelview");
// Initialize geometric shapes
initBufferObjects();
initTeapot(); initCube(); initSphere();
}*/
int main(int argc, char* argv[]) {
if (argc < 2) {
cerr << "Usage: transforms scenefile [grader input (optional)]\n";
exit(-1);
}
FreeImage_Initialise();
// glutInit(&argc, argv);
// OSX systems require an extra window init flag
/*#ifdef __APPLE__
glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
#else
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
#endif
glutCreateWindow("HW2: Scene Viewer");
*/
/*#ifndef __APPLE__ // GLew not needed on OSX systems
GLenum err = glewInit() ;
if (GLEW_OK != err) {
std::cerr << "Error: " << glewGetString(err) << std::endl;
}
#endif*/
//init();
readfile(argv[1]) ;
display();
/* glutDisplayFunc(display);
glutSpecialFunc(specialKey);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutReshapeWindow(w, h);
*/
/* if (argc > 2) {
//allowGrader = true;
stringstream tcid;
tcid << argv[1] << "." << argv[2];
grader.init(tcid.str());
grader.loadCommands(argv[2]);
grader.bindDisplayFunc(display);
grader.bindSpecialFunc(specialKey);
grader.bindKeyboardFunc(keyboard);
grader.bindScreenshotFunc(saveScreenshot);
}*/
printHelp();
//glutMainLoop();
FreeImage_DeInitialise();
// destroyBufferObjects();
return 0;
}