Skip to content

Commit

Permalink
fix: torus texture coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 26, 2024
1 parent 3fb8751 commit 9611197
Show file tree
Hide file tree
Showing 6 changed files with 624 additions and 13 deletions.
2 changes: 1 addition & 1 deletion engine/include/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Light createPointLight(glm::vec4 position);

Light createSpotLight(glm::vec4 position, glm::vec4 direction, float cutoff);

void setupLights(std::vector<Light> lights);
bool setupLights(std::vector<Light> lights);

void drawLights(std::vector<Light> lights);

Expand Down
5 changes: 4 additions & 1 deletion engine/src/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void setupMaterial(Material m) {
glMaterialf(GL_FRONT, GL_SHININESS, m.shininess);
}

void setupLights(std::vector<Light> lights) {
bool setupLights(std::vector<Light> lights) {
if (lights.size() != 0) {
glEnable(GL_RESCALE_NORMAL);
float amb[4] = {1.0f, 1.0f, 1.0f, 1.0f};
Expand All @@ -59,7 +59,10 @@ void setupLights(std::vector<Light> lights) {
glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, white);
glLightfv(GL_LIGHT0 + i, GL_SPECULAR, white);
}
return true;
}

return false;
}

void drawLights(std::vector<Light> lights) {
Expand Down
9 changes: 5 additions & 4 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bool axis = true;
bool wireframe = false;
bool normals = false;
bool culling = false;
bool lighting = false;

int timebase;
float frames;
Expand Down Expand Up @@ -105,6 +106,7 @@ void renderMenu() {
ImGui::Checkbox("Wireframe", &wireframe);
ImGui::Checkbox("Normals", &normals);
ImGui::Checkbox("Frustsum", &culling);
ImGui::Checkbox("Lighting", &lighting);
ImGui::Button("Reset", ImVec2(50, 20));
if (ImGui::IsItemClicked()) {
resetCamera();
Expand Down Expand Up @@ -157,12 +159,11 @@ void renderScene(void) {
fillMode();
drawAxis();

bool lights = c.lights.size() != 0;
if (lights) {
if (lighting) {
drawLights(c.lights);
}

c.group.drawGroup(lights, frustsum, normals);
c.group.drawGroup(lighting, frustsum, normals);

// Start the Dear ImGui frame
renderMenu();
Expand Down Expand Up @@ -250,7 +251,7 @@ int main(int argc, char** argv) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
setupLights(c.lights);
lighting = setupLights(c.lights);
setupModels(c.group);

// enter GLUT�s main cycle
Expand Down
10 changes: 5 additions & 5 deletions generator/src/shapes/torus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ torusAllPoints(float majorRadius, float minorRadius, int sides, int rings) {
normals.push_back(n3);

// Texture coordinates
float u1 = static_cast<float>(i) / static_cast<float>(rings);
float u2 = static_cast<float>(i + 1) / static_cast<float>(rings);
float v1 = static_cast<float>(j) / static_cast<float>(sides);
float v2 = static_cast<float>(j + 1) / static_cast<float>(sides);
float u1 = static_cast<float>(j) / static_cast<float>(sides);
float u2 = static_cast<float>(j + 1) / static_cast<float>(sides);
float v1 = static_cast<float>(i) / static_cast<float>(rings);
float v2 = static_cast<float>(i + 1) / static_cast<float>(rings);

textures.push_back(Point2D(u1, v1));
textures.push_back(Point2D(u2, v1));
Expand Down Expand Up @@ -111,4 +111,4 @@ bool generateTorus(float majorRadius, float minorRadius, int sides, int rings,
}

return true;
}
}
Loading

0 comments on commit 9611197

Please sign in to comment.