46 constexpr static float defaultCoreRadius = 0.20f;
47 constexpr static float animCoreRadiusHalfStep = 0.015f;
50 float m_radius = 1.00f;
54 GLUniformSyncPMVMat4f m_pmvMatUni;
56 GLUniformVec4f m_uWinCenter;
57 GLUniformVec4f m_uCoreColor, m_uHaloColor, m_uBackColor;
58 GLUniformScalarF32 m_uWinRadius, m_uCoreRadius, m_uSeam;
61 jau::fraction_timespec m_tlast;
63 class MyKeyListener :
public KeyListener {
67 void keyPressed(KeyEvent &e,
const KeyboardTracker &kt)
override {
69 if (e.
keySym() == VKeyCode::VK_ESCAPE) {
74 }
else if (e.
keySym() == VKeyCode::VK_W) {
79 void keyReleased(KeyEvent &e,
const KeyboardTracker &kt)
override {
83 typedef std::shared_ptr<MyKeyListener> MyKeyListenerRef;
84 MyKeyListenerRef m_kl;
90 m_pmvMatUni(
"gcu_PMVMatrix"),
91 m_uWinCenter(
"gcu_solInSpace.winCenter",
Vec4f()),
92 m_uCoreColor(
"gcu_solInSpace.coreColor",
Vec4f(1.0f, 1.0f, 0.0f, 1.0f)),
93 m_uHaloColor(
"gcu_solInSpace.haloColor",
Vec4f(1.0f, 0.99f, 0.0f, 1.0f)),
94 m_uBackColor(
"gcu_solInSpace.bgColor",
Vec4f(0.0f, 0.0f, 0.0f, 0.5f)),
95 m_uWinRadius(
"gcu_solInSpace.winRadius", 0),
96 m_uCoreRadius(
"gcu_solInSpace.coreRadius", defaultCoreRadius),
97 m_uSeam(
"gcu_solInSpace.seam", 0.005f),
99 m_kl(
std::make_shared<MyKeyListener>(*this))
101 m_st.manage(m_pmvMatUni);
103 m_st.manage(m_uWinCenter);
104 m_st.manage(m_uCoreColor);
105 m_st.manage(m_uHaloColor);
106 m_st.manage(m_uBackColor);
107 m_st.manage(m_uWinRadius);
108 m_st.manage(m_uCoreRadius);
109 m_st.manage(m_uSeam);
116 const PMVMat4f&
pmv() const noexcept {
return m_pmvMatUni.pmv(); }
128 "demos/glsl/bin",
"default");
130 "demos/glsl/bin",
"SolInSpace");
139 if( !sp0->
add(
gl, vp0,
true) || !sp0->
add(
gl, fp0,
true) ) {
145 m_st.attachShaderProgram(
gl, sp0,
true);
149 pmv.getP().loadIdentity();
150 pmv.getMv().loadIdentity();
154 ::glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
155 m_uBackColor.vec4f().set(0.0f, 0.0f, 0.0f, 0.5f);
159 vertices->reserve(4);
160 vertices->put( { -m_radius, m_radius, 0,
161 m_radius, m_radius, 0,
162 -m_radius, -m_radius, 0,
163 m_radius, -m_radius, 0 } );
164 m_st.manage(vertices);
165 vertices->seal(
gl,
true);
167 ::glEnable(GL_DEPTH_TEST);
169 m_initialized = sp0->
inUse();
170 if( m_initialized ) {
171 m_st.sendAllUniforms(
gl);
177 m_st.useProgram(
gl,
false);
180 return m_initialized;
187 pmv.mapObjToWin(m_center, m_viewport, winCenter);
188 m_uWinCenter.vec4f().set(winCenter, 1.0f);
190 const Vec3f p1 = m_center +
Vec3f(m_radius,0,0);
192 pmv.mapObjToWin(p1, m_viewport, winP1);
193 Vec3f winR = winP1 - winCenter;
194 m_uWinRadius.scalar() = winR.
length();
196 m_st.send(
gl, m_uWinCenter);
197 m_st.send(
gl, m_uWinRadius);
204 m_initialized =
false;
212 const float aspect = 1.0f;
213 const float fovy_deg=45.0f;
214 const float aspect2 = ( (float) m_viewport.width() / (
float) m_viewport.height() ) / aspect;
215 const float zNear=1.0f;
216 const float zFar=100.0f;
219 pmv.getMv().loadIdentity();
220 pmv.translateMv(0, 0, -3);
222 m_st.useProgram(
gl,
true);
223 m_st.send(
gl, m_pmvMatUni);
225 m_st.useProgram(
gl,
false);
232 if( !m_initialized ) {
236 ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
238 m_st.useProgram(
gl,
true);
240 static float dr_dir = 1;
241 constexpr float dr_min = defaultCoreRadius * 1.0f-animCoreRadiusHalfStep;
242 constexpr float dr_max = defaultCoreRadius * 1.0f+animCoreRadiusHalfStep;
243 const float dt = (float)(when - m_tlast).to_ms() / 1000.0f;
244 float r = m_uCoreRadius.scalar() + animCoreRadiusHalfStep * dt * dr_dir;
248 }
else if( r >= dr_max ) {
252 m_uCoreRadius.scalar() = r;
254 m_st.send(
gl, m_uCoreRadius);
256 std::cerr <<
"XXX: " << m_st <<
"\n";
261 ::glEnable(GL_BLEND);
262 ::glBlendEquation(GL_FUNC_ADD);
263 ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
267 ::glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
268 m_st.useProgram(
gl,
false);
273 std::string
toStringImpl() const noexcept
override {
return "SolInSpace"; }
276int main(
int argc,
char *argv[])
278 return launch(
"SolInSpace",
280 std::make_shared<Example>(), argc, argv);
int launch(std::string_view sfile, GLLaunchProps props, const RenderListenerSRef &demo, int argc, char *argv[])
int main(int argc, char *argv[])
void reshape(const WindowSRef &win, const jau::math::Recti &viewport, const jau::fraction_timespec &when) override
Called by the drawable during the first repaint after the component has been resized.
void display(const WindowSRef &win, const jau::fraction_timespec &when) override
Called by the drawable to initiate rendering by the client.
PMVMat4f & pmv() noexcept
bool init(const WindowSRef &win, const jau::fraction_timespec &when) override
Called by the drawable immediately after the render context is initialized.
const Recti & viewport() const noexcept
const PMVMat4f & pmv() const noexcept
void updateSolSpatial(GL &gl)
Recti & viewport() noexcept
std::string toStringImpl() const noexcept override
void dispose(const WindowSRef &win, const jau::fraction_timespec &when) override
Notifies the listener to perform the release of all renderer resources per context,...
Specifies a set of OpenGL capabilities.
static GLContext & downcast(RenderContext *rc)
Downcast dereferenced given RenderContext* to GLContext&, throws exception if signature doesn't match...
Specifies the OpenGL profile.
static constexpr std::string_view GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
static server_sref createGLSL(std::string_view name, GLsizei compsPerElement, bool normalized, GLsizei initialElementCount, GLenum vboUsage)
size_t defaultShaderCustomization(const GL &gl, bool preludeVersion=true, bool addDefaultPrecision=true, bool addDefaultDefines=true)
Default customization of this shader source code.
static ShaderCodeSRef create(GLenum type, size_t count, const source_list_t &sources)
static ShaderProgramSRef create() noexcept
void destroy(GL &gl) noexcept
Detaches all shader codes and deletes the program.
bool add(const ShaderCodeSRef &shaderCode) noexcept
Adds a new shader to this program.
constexpr bool inUse() const noexcept
constexpr RenderListener(Private) noexcept
Private ctor for shared_ptr<RenderListener> instance method w/o public ctor.
std::string toString() const noexcept
const gamp::render::RenderContext * renderContext() const noexcept
void addKeyListener(const KeyListenerSRef &l)
void dispose(const jau::fraction_timespec &when) noexcept override
size_t removeKeyListener(const KeyListenerSRef &l)
std::string toString() const noexcept
std::string toString() const noexcept
constexpr VKeyCode keySym() const noexcept
Returns the virtual key symbol reflecting the current keyboard layout.
virtual const PressedKeyCodes & pressedKeyCodes() const noexcept=0
constexpr const WindowWeakPtr & source() const noexcept
constexpr const jau::fraction_timespec & when() const noexcept
size_type count() const noexcept
constexpr value_type length() const noexcept
Return the length of a vector, a.k.a the norm or magnitude
constexpr T adeg_to_rad(const T arc_degree) noexcept
Converts arc-degree to radians.
GLArrayDataServerSRef< float > GLFloatArrayDataServerSRef
std::shared_ptr< ShaderCode > ShaderCodeSRef
std::shared_ptr< ShaderProgram > ShaderProgramSRef
@ verbose
Verbose operations (debugging).
std::shared_ptr< Window > WindowSRef
PMVMatrix4< float > PMVMat4f
ssize_t fprintf_td(const uint64_t elapsed_ms, FILE *stream, std::string_view format, const Args &...args) noexcept
Convenient secure fprintf() invocation, prepending the given elapsed_ms timestamp and using jau:forma...
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...
constexpr uint64_t to_ms() const noexcept
Returns time in milliseconds.