-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98056d4
commit 9cdc858
Showing
11 changed files
with
259 additions
and
64 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef LIGHT_HPP | ||
#define LIGHT_HPP | ||
|
||
extern "C" { | ||
#include <GL/gl.h> | ||
#ifdef __APPLE_CC__ | ||
#include <GLUT/glut.h> | ||
#else | ||
#include <GL/freeglut.h> | ||
#endif | ||
} | ||
#include <glm/glm.hpp> | ||
#include <glm/gtc/type_ptr.hpp> | ||
|
||
enum LightType { DIRECTIONAL, POINT, SPOT }; | ||
|
||
typedef struct { | ||
LightType type; | ||
glm::vec4 position; | ||
glm::vec4 direction; | ||
float cutoff; | ||
} Light; | ||
|
||
Light createDirectionLight(glm::vec4 direction); | ||
|
||
Light createPointLight(glm::vec4 position); | ||
|
||
Light createSpotLight(glm::vec4 position, glm::vec4 direction, float cutoff); | ||
|
||
void setupLights(std::vector<Light> lights); | ||
|
||
typedef struct { | ||
glm::vec4 ambient; | ||
glm::vec4 diffuse; | ||
glm::vec4 specular; | ||
glm::vec4 emission; | ||
float shininess; | ||
} Material; | ||
|
||
Material createMaterial(glm::vec4 ambient, glm::vec4 diffuse, | ||
glm::vec4 specular, glm::vec4 emission, | ||
float shininess); | ||
|
||
void setupMaterial(Material m); | ||
|
||
#endif // LIGHT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "light.hpp" | ||
|
||
Light createDirectionLight(glm::vec4 direction) { | ||
Light light; | ||
light.type = DIRECTIONAL; | ||
light.direction = direction; | ||
return light; | ||
} | ||
|
||
Light createPointLight(glm::vec4 position) { | ||
Light light; | ||
light.type = POINT; | ||
light.position = position; | ||
return light; | ||
} | ||
|
||
Light createSpotLight(glm::vec4 position, glm::vec4 direction, float cutoff) { | ||
Light light; | ||
light.type = SPOT; | ||
light.position = position; | ||
light.direction = direction; | ||
light.cutoff = cutoff; | ||
return light; | ||
} | ||
|
||
Material createMaterial(glm::vec4 ambient, glm::vec4 diffuse, | ||
glm::vec4 specular, glm::vec4 emission, | ||
float shininess) { | ||
Material material; | ||
material.ambient = ambient; | ||
material.diffuse = diffuse; | ||
material.specular = specular; | ||
material.emission = emission; | ||
material.shininess = shininess; | ||
return material; | ||
} | ||
|
||
void setupMaterial(Material m) { | ||
glMaterialfv(GL_FRONT, GL_AMBIENT, glm::value_ptr(m.ambient)); | ||
glMaterialfv(GL_FRONT, GL_DIFFUSE, glm::value_ptr(m.diffuse)); | ||
glMaterialfv(GL_FRONT, GL_SPECULAR, glm::value_ptr(m.specular)); | ||
glMaterialfv(GL_FRONT, GL_EMISSION, glm::value_ptr(m.emission)); | ||
glMaterialf(GL_FRONT, GL_SHININESS, m.shininess); | ||
} | ||
|
||
void setupLights(std::vector<Light> lights) { | ||
for (int i = 0; i < lights.size() && lights.size() < 8; i++) { | ||
Light light = lights[i]; | ||
switch (light.type) { | ||
case DIRECTIONAL: | ||
glLightfv(GL_LIGHT0 + i, GL_POSITION, glm::value_ptr(light.direction)); | ||
break; | ||
case POINT: | ||
glLightfv(GL_LIGHT0 + i, GL_POSITION, glm::value_ptr(light.position)); | ||
break; | ||
case SPOT: | ||
glLightfv(GL_LIGHT0 + i, GL_POSITION, glm::value_ptr(light.position)); | ||
glLightfv(GL_LIGHT0 + i, GL_SPOT_DIRECTION, glm::value_ptr(light.direction)); | ||
glLightf(GL_LIGHT0 + i, GL_SPOT_CUTOFF, light.cutoff); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.