Files
cuber/scenes/sphere.hpp
T
portersky 78d0515e8b feat: add sphere scene with fixed cube-to-sphere mapping
Added scenes/sphere.{hpp,cpp} using the cube-to-sphere
approach from nrz.cpp, but with corrected math: vertices
are simply normalized to project onto the unit sphere
(the original used a broken formula with p=50.0 as an
exponent).

The sphere uses indexed geometry with position, normal,
and UV attributes, plus a simple diffuse lighting shader.

Press 1/2 to switch between cube and sphere scenes.
Updated .gitignore to exclude generated PNG screenshots.
2026-05-05 23:54:48 +02:00

40 lines
762 B
C++

#pragma once
#include <chrono>
#include "glm/glm.hpp"
#include "cbt/scene.hpp"
#include "cbt/opengl/buffer.hpp"
#include "cbt/opengl/shader.hpp"
#include "cbt/opengl/vao.hpp"
namespace cbt::scenes {
class sphere final : public scene {
public:
sphere();
auto init() -> bool override;
auto update(float delta_time) -> void override;
auto render() -> void override;
private:
opengl::shader m_prog;
opengl::buffer m_vbo;
opengl::buffer m_ebo{opengl::buffer_type::index};
opengl::vao m_vao;
GLint m_loc_proj = -1;
GLint m_loc_view = -1;
GLint m_loc_model = -1;
GLsizei m_index_count = 0;
std::chrono::steady_clock::time_point m_start;
auto build_mesh() -> void;
auto build_shader() -> bool;
};
}