Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9ccda7f
Include paths fixed
preparationh67 Sep 19, 2014
80c5222
Merge branch 'master' of https://github.com/CreativeCodingLab/aluminum
preparationh67 Oct 27, 2014
9378564
Output program name when using start(name)
preparationh67 Oct 27, 2014
ee39a16
Log SEGFAULT workaround for AMD graphics cards
preparationh67 Oct 27, 2014
364e3e1
Update Model.cpp
preparationh67 Oct 27, 2014
40aa06b
Added noise displacement shere example
preparationh67 Oct 27, 2014
d166330
Merge branch 'master' of github.com:preparationh67/aluminum
preparationh67 Oct 27, 2014
324a2be
Merge branch 'master' of https://github.com/CreativeCodingLab/aluminum
preparationh67 Nov 20, 2014
db8f880
Week1 Example First Check
preparationh67 Dec 1, 2014
2dc6bef
Updated and working and linux
preparationh67 Dec 1, 2014
7f3daa7
Week2b example on linux
preparationh67 Dec 1, 2014
1e68c82
Updated to work with keyboard
preparationh67 Dec 1, 2014
d4f0dfd
Updated to included working keyboard
preparationh67 Dec 1, 2014
7eabcd5
Week3a example (broken on linux)
preparationh67 Dec 1, 2014
a49bfe0
FBO Linux Example added
preparationh67 Dec 1, 2014
2cbe56d
Week3C Linux Example
preparationh67 Dec 1, 2014
51360f4
Linux Example Week4a, broken rotate function call
preparationh67 Dec 1, 2014
c29a3d8
Week4b Linux Example, Runtime Error, Bad Alloc
preparationh67 Dec 2, 2014
f51372c
Linux Example for week5a
preparationh67 Dec 2, 2014
538c64e
Linux Example for week5b, loadCubeMapTexture function missing in linux
preparationh67 Dec 2, 2014
8c4da32
Forgot main method
preparationh67 Dec 2, 2014
402177d
Linux Example Week5c same problem as 5b
preparationh67 Dec 2, 2014
5df6992
Linux Week5d Example, broken
preparationh67 Dec 2, 2014
7171202
Linux Week6a Working Example
preparationh67 Dec 2, 2014
63b0e61
Week6b Example, compiles and runs, unknown if working
preparationh67 Dec 2, 2014
be85297
Merge branch 'linux-examples2'
preparationh67 Dec 2, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 61 additions & 36 deletions linux/FreeGlutGLView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int width;
int height;
RendererLinux* renderer;
//static struct timeval lastTime;
static std::clock_t lastTime = std::clock();
static std::clock_t lastTime = std::clock();

FreeGlutGLView::FreeGlutGLView() {}

Expand All @@ -28,51 +28,52 @@ void reshape(GLint _w, GLint _h) {
}

void display() {
renderer->tick();
renderer->tick();
//printf("in FreeGlutGLView : display()\n");
renderer->onFrame();
glutSwapBuffers();
}

void animate() {
renderer->frameCount++;
/*
time = glutGet(GLUT_ELAPSED_TIME);
if (time - timebase > 1000) {
printf("FPS:%4.2f\n",
renderer->frameCount*1000.0 / (time - timebase));
timebase = time;
renderer->frameCount = 0;
}
*/

/*
float dt;

struct timeval now;
gettimeofday(&now, NULL);
dt = (float)(now.tv_usec - lastTime.tv_usec);
lastTime = now;
*/
renderer->frameCount++;
/*
time = glutGet(GLUT_ELAPSED_TIME);
if (time - timebase > 1000) {
printf("FPS:%4.2f\n",
renderer->frameCount*1000.0 / (time - timebase));
timebase = time;
renderer->frameCount = 0;
}
*/

/*
float dt;

struct timeval now;
gettimeofday(&now, NULL);
dt = (float)(now.tv_usec - lastTime.tv_usec);
lastTime = now;
*/
glutPostRedisplay();
}

void pressed(int button, int state, int x, int y ) {
// printf("button : %d %d %d %d\n", button, state, x, y);
// printf("button : %d %d %d %d\n", button, state, x, y);
//check state to see if sending down or up...
renderer->mouseDown(x,y);
}
void dragged(int x, int y ) {
// printf("motion : %d %d\n", x, y);
// printf("motion : %d %d\n", x, y);
renderer->mouseDragged(x,y);
}
void moved(int x, int y ) {
// printf("motion : %d %d\n", x, y);
// printf("motion : %d %d\n", x, y);
renderer->mouseMoved(x,y);
}


void keyboard(unsigned char key, int x, int y) {
renderer->keyboard(key,x,y);
switch(key) {

case 27:
Expand All @@ -93,6 +94,29 @@ void keyboard(unsigned char key, int x, int y) {
printf("done pressing...\n");
}


void specialkeys(int key, int x, int y) {
renderer->specialkeys(key,x,y);

switch (key) {

case GLUT_KEY_UP:
std::cout << "UP\n";
break;
case GLUT_KEY_DOWN:
std::cout << "DOWN\n";
break;
case GLUT_KEY_RIGHT:
std::cout << "RIGHT\n";
break;
case GLUT_KEY_LEFT:
std::cout << "LEFT\n";
break;

}

}

FreeGlutGLView* FreeGlutGLView::start(void* _renderer) {
return FreeGlutGLView::start(_renderer, "allomin");
}
Expand All @@ -113,28 +137,29 @@ FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name) {
glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

/*
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE );
GLint buf, sample;
glGetIntegerv (GL_SAMPLE_BUFFERS, &buf);
glGetIntegerv (GL_SAMPLES, &sample);
/*
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE );
GLint buf, sample;
glGetIntegerv (GL_SAMPLE_BUFFERS, &buf);
glGetIntegerv (GL_SAMPLES, &sample);

std::cout << "buf: " << buf << " samples: " << sample << " \n";
glEnable(GL_MULTISAMPLE);
*/
std::cout << "buf: " << buf << " samples: " << sample << " \n";
glEnable(GL_MULTISAMPLE);
*/

glutInitWindowSize(200,200);
glutCreateWindow(name.c_str());

// glutGameModeString("1280x1024:32@60");
// glutEnterGameMode();
renderer->setStartTick();
// glutGameModeString("1280x1024:32@60");
// glutEnterGameMode();
renderer->setStartTick();

renderer->onCreate();

glutDisplayFunc(&display);
glutReshapeFunc(&reshape);
glutKeyboardFunc(&keyboard);
glutSpecialFunc(&specialkeys);
glutMouseFunc(&pressed);
glutMotionFunc(&dragged);
glutPassiveMotionFunc(&moved);
Expand Down
6 changes: 6 additions & 0 deletions linux/README_LINUX_CONFIG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ Install FreeGlut2.6+ and GL3:
sudo apt-get install freeglut3-dev

Copy http://www.opengl.org/registry/api/gl3.h to /usr/include/GL3/gl3.h (NOTE this should be necessary with newest version of freeglut!!!)

****
IMPORTANT IF USING AN AMD GRAPHICS CARD!
****
For some reason a bad logging call is made in Program.cpp which causes the program to SEGFAULT if using an AMD graphics card.
Uncomment the line AMD_HACK in scripts/makeStaticLibrary.sh to enable a bypass of this call
5 changes: 3 additions & 2 deletions linux/RendererLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void RendererLinux::start() {
FreeGlutGLView::start(this);
}
void RendererLinux::start(std::string name) {
printf("in RendererLinux::start(name)\n");
printf("in RendererLinux::start(%s)\n", name.c_str());
FreeGlutGLView::start(this, name);
}

Expand Down Expand Up @@ -64,7 +64,8 @@ void RendererLinux::mouseDragged(int px, int py) {}
void RendererLinux::mouseDown(int px, int py) {}
void RendererLinux::mouseUp(int px, int py) {}
void RendererLinux::mouseMoved(int px, int py) {}

void RendererLinux::keyboard(unsigned char key, int x, int y) {}
void RendererLinux::specialkeys(int key, int x, int y) {}


//}
Expand Down
3 changes: 2 additions & 1 deletion linux/RendererLinux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ virtual void mouseDragged(int px, int py);
virtual void mouseDown(int px, int py);
virtual void mouseUp(int px, int py);
virtual void mouseMoved(int px, int py);

virtual void keyboard(unsigned char key, int x, int y);
virtual void specialkeys(int key, int x, int y);



Expand Down
180 changes: 180 additions & 0 deletions linux/class-examples/week1_BasicShader/BasicColor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#include <Aluminum/Includes.hpp>

#include "Aluminum/FreeGlutGLView.hpp"
#include "Aluminum/RendererLinux.hpp"
#include "Aluminum/MeshBuffer.hpp"
#include "Aluminum/MeshUtils.hpp"
#include "Aluminum/Program.hpp"
#include "Aluminum/ResourceHandler.hpp"

#define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i))

using namespace aluminum;


/* Simple demo that draws two triangles */
class Basic : public RendererLinux {
public:

//The ResourceHandler object manages external resources, such as text files containing shader programs, image files, video files, and assets.
ResourceHandler rh;

//A Program object manages the loading, compiling, and interacting with a shader program
Program program;

//OpenGL IDs for a default vertex array object, a vertex buffer object, and an index buffer object that will stored on the GPU.
GLuint vao, vbo, ibo;

//Defines six indices to represent the two triangles made from the four vertices.
GLuint indices[6];

//Defines an array of vertex data; 3 vec3s of position, followed by 3 vec3s of color info
vec3 vertices[8];

//Defines the default locations for the attribute variables in the vertex shader
GLint posLoc = 0;
GLint colLoc = 1;

//mat4s for the projections matrix and modelview matrix passed in as uniforms to the vertex shader
mat4 proj, mv;


void loadProgram(Program &p, const std::string& name) {

//Initializes a Program object
p.create();

//Gets the path to the vertex shader (ending in ".vsh")
string sv = rh.pathToResource(name, "vsh");
// cout << "path of vertex shader is: " << sv << endl;

//Compiles the vertex shader and attaches it to our Program object
p.attach(rh.contentsOfFile(sv), GL_VERTEX_SHADER);

//Binds attribute variables to a particular ID
glBindAttribLocation(p.id(), posLoc, "vertexPosition");
glBindAttribLocation(p.id(), colLoc, "vertexColor");


//Gets the path to the fragment shader (ending in ".fsh")
string sp = rh.pathToResource(name, "fsh");
// cout << "path of vertex shader is: " << sp << endl;

//Compiles the fragment shader and attaches it to our Program object
p.attach(rh.contentsOfFile(sp), GL_FRAGMENT_SHADER);

//Links the Program object to the GPU so that it can be activated when needed
p.link();
}

//onCreate runs one time right after the OpenGL context is established. A good place to load shaders, load textures, set up vertex data, initialize global parameters.
virtual void onCreate() {

//** Step 0 **//
// An unfortunate function of Microsofts lack of adopting C++11 standards quickly enough is evidenced by the inability to specify explicit initializer for arrays
// so we are forced to perform this additional step.

//Defines six indices to represent the two triangles made from the four vertices.
GLuint _indices[6] = { 0, 1, 2, 2, 1, 3 };
std::memcpy(indices, _indices, sizeof indices);

//Defines an array of vertex data; 3 vec3s of position, followed by 3 vec3s of color info
vec3 _vertices[8] = {
vec3(-1.0, -1.0, 0.0), vec3(-1.0, 1.0, 0.0), vec3(1.0, -1.0, 0.0), vec3(1.0, 1.0, 0.0), //vertex
vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(1.0, 1.0, 1.0) //color
};
std::memcpy(vertices, _vertices, sizeof vertices);

//** Step 1 **//

// Load our shader program, by default looks for two files, a .vsh file and .fsh file
loadProgram(program, "resources/basic_s");

//** Step 2 **//

// Create a vertex array object to store geometry and related information (the buffer of data itself, the layout of the data, and how the data is indexed).
glGenVertexArrays(1, &vao); //allocate space for a VAO on the GPU
glBindVertexArray(vao); //activate this space so we can store information there

// Create and initialize a vertex buffer object to store geometry data
glGenBuffers(1, &vbo); //allocate space for vertex data on the GPU
glBindBuffer(GL_ARRAY_BUFFER, vbo); //activate this space so we can store vertex data there
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_DYNAMIC_DRAW); //pass data to the GPU

//These two commands first enable the variable referenced by the ID stored in "posLoc" to receive data into the "vertexPosition" variable in the vertexShader (see the loadProgram method above), and then explain how to map the data in our "vertices" array to this vertexPosition variable when its streamed in.
//The glVertexAttribPointer method defines the location and format of data mapped to a particular attribute. Here we are using a vec3 to store the x,y, and z position information (i.e., 3 floats). They will be read in from the beginning of our vertices array.
glEnableVertexAttribArray(posLoc); //enable this variable ("vertexPosition") to receive vertex data
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0 * sizeof(vec3))); //define how the data will be mapped to the "vertexPosition" variable

//Similar to above, we enable the "vertexColor" variable associated with the "colLoc" ID and provide the location and format of the color data within our vertices array. We are using a vec3 to store an RGB color (i.e., 3 floats), and this data is located starting from the vec3 at index 4 (i.e., after the four position vec3s).
glEnableVertexAttribArray(colLoc);
glVertexAttribPointer(colLoc, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(4 * sizeof(vec3)));

//An index buffer object is used to more efficiently pass a single vertex that can be used more than once (i.e., a point shared with multiple triangles). In this example, Index 0 will point to a position at the zeroth vec3 in the data array and a color at the fourth vec3 in the data array. Index 1 will point to the first vec3 and the fifth vec3, etc... The indexes are repeated because the second triangle shares two vertices with the previous triangle.
glGenBuffers(1, &ibo); //allocate space for the indices on the GPU
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); //activate this space so we can store indices there
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)* 6, indices, GL_DYNAMIC_DRAW);

//** Step 3 **//

// Set up Modelview and Projection matrix
proj = glm::perspective(45.0, 1.0, 0.1, 100.0); //defines how to project 3D data to 2D image
mv = glm::lookAt(vec3(0, 0, 2.5), vec3(0, 0, 0), vec3(0, 1, 0)); //defines where the camera is positioned
}

//onFrame syncs with the refresh rate of the display (e.g., 60fps). Here we can send information to the GPU to define exactly how the pixels on the window should look.
virtual void onFrame(){

glViewport(0, 0, width, height); //defines the active viewport to match the size of our window
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clears color and depth info from the viewport


// the program.bind() activates our shader program so that we can 1. pass data to it and 2. let it draw to the active viewport in our window
program.bind(); {

glUniformMatrix4fv(program.uniform("mv"), 1, 0, ptr(mv)); //pass in the view matrix
glUniformMatrix4fv(program.uniform("proj"), 1, 0, ptr(proj)); //pass in the projection matrix

glBindVertexArray(vao); //binds our vertex array object, containing all our data and information about how it's organized and indexed
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); //passes the entire data buffer to the GPU as a set of triangles; that is, read the index array three items at a time.

glBindVertexArray(0);
} program.unbind();

}

//examples of how to react to a mouse event
void mouseDragged(int px, int py) {
printf("in Basic: mouseDragged %d/%d\n", px, py);
}

void mouseMoved(int px, int py) {
printf("in Basic: mouseMoved %d/%d\n", px, py);
}

void mouseDown(int px, int py) {
printf("in Basic: mouseDown %d/%d\n", px, py);
}

void mouseUp(int px, int py) {
printf("in Basic: mouseUp %d/%d\n", px, py);
}


//examples of how to react to a key event
void keyboard(unsigned char key, int x, int y) {
//printf("in Basic: key = %c, shift=%d, control=%d, command=%d, option=%d, function=%d\n", key, shift, control, command, option, function);

switch (key) {
case 'a':
printf("you pressed an 'A'! \n");
break;
}
}

};

int main(){
Basic().start("BasicColor");
return 0;
}
8 changes: 8 additions & 0 deletions linux/class-examples/week1_BasicShader/resources/basic_s.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 150

out vec4 outputFrag;
in vec4 color;

void main() {
outputFrag = color;
}
Loading