1. Introduction In this assignment, we will practice some of the basics of OpenGL. 2. Setup a. Create a C++ project on repl.it b. Delete main.cpp that was created in default, and upload the starter files (main.cpp, script.sh) to the project. c. Upload freeglut library, which is freeglut-3.2.1.tar.gz (please don’t extract it before upload), and right now, the directory should be looking like d. Extract it on replit console using the following command: tar -xzvf freeglut-3.2.1.tar.gz Then the directory should be like e. Get permission to read and execute script.sh by using the following command: chmod u=rx script.sh f. Then run script.sh by using ./script.sh (Instead of run button, you must run this command every time to compile.) Then it will generate a window showing your result. (It may take some time for the first time)

1. Introduction
In this assignment, we will practice some of the basics of OpenGL.
2. Setup
a. Create a C++ project on repl.it
b. Delete main.cpp that was created in default, and upload the starter files (main.cpp, script.sh) to the project.
c. Upload freeglut library, which is freeglut-3.2.1.tar.gz (please don’t extract it before upload), and right now,
the directory should be looking like
d. Extract it on replit console using the following command: tar -xzvf freeglut-3.2.1.tar.gz
Then the directory should be like
e. Get permission to read and execute script.sh by using the following command: chmod u=rx script.sh
f. Then run script.sh by using ./script.sh (Instead of run button, you must run this command every time to
compile.)
Then it will generate a window showing your result. (It may take some time for the first time)
3. The Main Assignment
For this homework, you will be using your newfound OpenGL skills from class, as well as your artistic
creativity, to create several 3D scenes with OpenGL. The first part of the assignment is to write code to
reproduce each of the following three images:
The second part of the assignment is to create, using similar techniques, a scene of your own imagination.
All the code for this homework lives in main.cpp; you need to fill in the functions problem1, problem2,
problem3, and problem4. You can switch between the different examples while the program is running by
pressing the 1,2, . . . keys. Hence you don’t need to recompile in order to run different examples. Additionally,
you can quit the program at any time by pressing ‘q’, ‘Q’, or the Escape key.
4. Tips and Requirements
For each of the three reproductions, you should be able to create the image using only glutSolidTeapot,
glutSolidCube, and OpenGL’s transformation mechanisms like glPushMatrix, glPopMatrix, glTranslatef, etc.
Note that you should not need any custom geometry, just the teapot and cube, to reproduce the images.
Your reproductions do not need to match exactly. However, please try to make them match the examples as
closely as possible. We used nice numbers in the reference solutions, so if you find yourself using strange
fractions etc. to reproduce the examples, you may be trying too hard!
For the open-ended image/scene, we require the following to make sure your image is interesting:
• Make use of OpenGL’s transformation mechanisms in a nontrivial way, with at least one instance
of nested applications of glPushMatrix (i.e., a glPushMatrix within another glPushMatrix).
• Render at least one triangle by feeding in its coordinates directly (OpenGL immediate mode is
okay here, even though it’s deprecated) As an example, you could attempt to create a very rough
approximation of an articulated hand
5. Deliverables
Submit all deliverables to your Github repository.
a. Code (main.cpp) for generating each of your four images (30%)
b. Screenshots (preferably .png) for each of your four images (20%)
c. You need to write a detailed report in pdf format. You should state the assignment problem, explain the
algorithm or method you use, explain details of implementation, discuss your results, etc. (50%)
6. Late submission and plagiarism check
A punishment deduction of 50% credit will be applied if your submission is later than the due date for less than
2 days. Later than that will be treated as give up, and the grade will be 0.
All your submissions will be subject to plagiarism check; if found, your behavior will be reported directly to the
department. Any referred materials should be labeled in your source code and declared in your report.
7. Reminder
The deadline for HW2 is the day right before the mid-term exam, so please start the HW earlier.

 

 

/*******************************************************
* Homework 2: OpenGL *
*—————————————————–*
* First, you should fill in problem1(), problem2(), *
* and problem3() as instructed in the written part of *
* the problem set. Then, express your creativity *
* with problem4()! *
* *
* Note: you will only need to add/modify code where *
* it says “TODO”. *
* *
* The left mouse button rotates, the right mouse *
* button zooms, and the keyboard controls which *
* problem to display. *
* *
* For Linux/OS X: *
* To compile your program, just type “make” at the *
* command line. Typing “make clean” will remove all *
* computer-generated files. Run by typing “./hw2” *
* *
* For Visual Studio: *
* You can create a project with this main.cpp and *
* build and run the executable as you normally would. *
*******************************************************/

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>

#include “./freeglut-3.2.1/include/GL/freeglut.h”

using namespace std;

bool leftDown = false, rightDown = false;
int lastPos[2];
float cameraPos[4] = {0,1,4,1};
int windowWidth = 640, windowHeight = 480;
double yRot = 0;
int curProblem = 1; // TODO: change this number to try different examples

float specular[] = { 1.0, 1.0, 1.0, 1.0 };
float shininess[] = { 50.0 };

void problem1() {
// TODO: Your code here!
}

void problem2() {
// TODO: Your code here!
}

void problem3() {
// TODO: Your code here!
}

void problem4() {
// TODO: Your code here!
}

void display() {
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glDisable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glBegin(GL_LINES);
glColor3f(1,0,0); glVertex3f(0,0,0); glVertex3f(1,0,0); // x axis
glColor3f(0,1,0); glVertex3f(0,0,0); glVertex3f(0,1,0); // y axis
glColor3f(0,0,1); glVertex3f(0,0,0); glVertex3f(0,0,1); // z axis
glEnd(/*GL_LINES*/);

glEnable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
glEnable(GL_LIGHT0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,windowWidth,windowHeight);

float ratio = (float)windowWidth / (float)windowHeight;
gluPerspective(50, ratio, 1, 1000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0, 0, 0, 0, 1, 0);

glLightfv(GL_LIGHT0, GL_POSITION, cameraPos);

glRotatef(yRot,0,1,0);

if (curProblem == 1) problem1();
if (curProblem == 2) problem2();
if (curProblem == 3) problem3();
if (curProblem == 4) problem4();

glutSwapBuffers();
}

void mouse(int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON) leftDown = (state == GLUT_DOWN);
else if (button == GLUT_RIGHT_BUTTON) rightDown = (state == GLUT_DOWN);

lastPos[0] = x;
lastPos[1] = y;
}

void mouseMoved(int x, int y) {
if (leftDown) yRot += (x – lastPos[0])*.1;
if (rightDown) {
for (int i = 0; i < 3; i++)
cameraPos[i] *= pow(1.1,(y-lastPos[1])*.1);
}

lastPos[0] = x;
lastPos[1] = y;
glutPostRedisplay();
}

void keyboard(unsigned char key, int x, int y) {
curProblem = key-‘0’;
if (key == ‘q’ || key == ‘Q’ || key == 27){
exit(0);
}
glutPostRedisplay();
}

void reshape(int width, int height) {
windowWidth = width;
windowHeight = height;
glutPostRedisplay();
}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(windowWidth, windowHeight);
glutCreateWindow(“HW2”);

glutDisplayFunc(display);
glutMotionFunc(mouseMoved);
glutMouseFunc(mouse);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);

glutMainLoop();

return 0;
}

 

 

 

# set up paths, the paths move around on repl
replrootpath=$PWD
cdate=$(date +%Y%m%dT%H%M%s)
backuptargetname=$target_file$cdate
backupsourcename=$source_file$cdate
examplebasepath=$replrootpath/freeglut-3.2.1/progs/demos/

# name your files here – this is your own thing to edit/complile in C++
source_file=$replrootpath/’main.cpp’
target_file=$replrootpath/’compiled’

# check if freeglut3-dev is installed on host
# install it if one of the library files isnt missing
# see output of >ldd triangle< from shell for more info
if [ ! -f ~/.apt/usr/lib/x86_64-linux-gnu/libglut.so.3 ]
then
install-pkg freeglut3-dev
fi

# performs versioning, checks mtime on file to see
# if cpp src file is modified newer than compiled binary
#if so then move it to backup dir and remake with g++
if [ “$source_file” -nt “$target_file” ]
then
g++ $source_file -lglut -lGL -lGLU -o $target_file
# chmod u+x .$target_file
fi

if [ $? -eq 0 ]; then
chmod u+x $target_file
$target_file
else
echo “Compile failed”
fi

# if we made it this far, start your program
# $target_file

 

 

 

COSC4370-HW2 freeglut-3.2.1.tar COSC4370_HW2

APA

 

 

 

CLICK HERE FOR FURTHER ASSISTANCE ON THIS ASSIGNMENT

The post 1. Introduction In this assignment, we will practice some of the basics of OpenGL. 2. Setup a. Create a C++ project on repl.it b. Delete main.cpp that was created in default, and upload the starter files (main.cpp, script.sh) to the project. c. Upload freeglut library, which is freeglut-3.2.1.tar.gz (please don’t extract it before upload), and right now, the directory should be looking like d. Extract it on replit console using the following command: tar -xzvf freeglut-3.2.1.tar.gz Then the directory should be like e. Get permission to read and execute script.sh by using the following command: chmod u=rx script.sh f. Then run script.sh by using ./script.sh (Instead of run button, you must run this command every time to compile.) Then it will generate a window showing your result. (It may take some time for the first time) appeared first on Apax Researchers.

Reference no: EM132069492

WhatsApp
Hello! Need help with your assignments? We are here

GRAB 25% OFF YOUR ORDERS TODAY

X