44 static constexpr float radius = 1.00f;
89 m_uCoreColor(
GLUniformVec4f::create(
"gcu_solInSpace.coreColor",
Vec4f(1.0f, 1.0f, 0.0f, 1.0f))),
90 m_uHaloColor(
GLUniformVec4f::create(
"gcu_solInSpace.haloColor",
Vec4f(1.0f, 0.99f, 0.0f, 1.0f))),
91 m_uBackColor(
GLUniformVec4f::create(
"gcu_solInSpace.bgColor",
Vec4f(0.0f, 0.0f, 0.0f, 0.5f))),
96 m_kl(
std::make_shared<MyKeyListener>(*this))
103 const PMVMat4f&
pmv() const noexcept {
return m_pmvMatUni->pmv(); }
113 "demos/glsl/bin",
"default");
115 "demos/glsl/bin",
"SolInSpace");
124 if( !sp0->
add(
gl, vp0,
true) || !sp0->
add(
gl, fp0,
true) ) {
130 m_st.attachShaderProgram(
gl, sp0,
true);
134 pmv.getP().loadIdentity();
135 pmv.getMv().loadIdentity();
136 m_st.ownUniform(m_pmvMatUni,
true);
138 m_st.ownUniform(m_uWinCenter,
true);
139 m_st.ownUniform(m_uCoreColor,
true);
140 m_st.ownUniform(m_uHaloColor,
true);
141 m_st.ownUniform(m_uBackColor,
true);
142 m_st.ownUniform(m_uWinRadius,
true);
143 m_st.ownUniform(m_uCoreRadius,
true);
144 m_st.ownUniform(m_uSeam,
true);
148 ::glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
149 m_uBackColor->vec4f().set(0.0f, 0.0f, 0.0f, 0.5f);
153 vertices->reserve(4);
158 m_st.ownAttribute(vertices,
true);
159 vertices->seal(
gl,
true);
161 ::glEnable(GL_DEPTH_TEST);
163 m_initialized = sp0->
inUse();
164 if( !m_initialized ) {
169 m_st.pushAllUniforms(
gl);
170 m_st.useProgram(
gl,
false);
173 return m_initialized;
180 m_initialized =
false;
188 const float aspect = 1.0f;
189 const float fovy_deg=45.0f;
190 const float aspect2 = ( (float) m_viewport.width() / (
float) m_viewport.height() ) / aspect;
191 const float zNear=1.0f;
192 const float zFar=100.0f;
196 m_st.useProgram(
gl,
true);
197 m_st.pushUniform(
gl, m_pmvMatUni);
198 m_st.useProgram(
gl,
false);
205 if( !m_initialized ) {
209 ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
211 m_st.useProgram(
gl,
true);
213 pmv.getMv().loadIdentity();
214 pmv.translateMv(0, 0, -3);
217 const Vec3f center(0,0,0);
219 pmv.mapObjToWin(center, m_viewport, winCenter);
220 m_uWinCenter->vec4f().set(winCenter, 1.0f);
224 pmv.mapObjToWin(p1, m_viewport, winP1);
225 Vec3f winR = winP1 - winCenter;
226 m_uWinRadius->scalar() = winR.
length();
228 static float dr_dir = 1;
231 const float dt = (float)(when - m_tlast).to_ms() / 1000.0f;
236 }
else if( r >= dr_max ) {
240 m_uCoreRadius->scalar() = r;
242 m_st.pushUniform(
gl, m_pmvMatUni);
243 m_st.pushUniform(
gl, m_uWinCenter);
244 m_st.pushUniform(
gl, m_uWinRadius);
245 m_st.pushUniform(
gl, m_uCoreRadius);
247 std::cerr <<
"XXX: " << m_st <<
"\n";
252 ::glEnable(GL_BLEND);
253 ::glBlendEquation(GL_FUNC_ADD);
254 ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
258 ::glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
259 m_st.useProgram(
gl,
false);
264 std::string
toStringImpl() const noexcept
override {
return "SolInSpace"; }
267int main(
int argc,
char *argv[])
269 return launch(
"SolInSpace",
271 std::make_shared<Example>(), argc, argv);
int launch(std::string_view sfile, GLLaunchProps props, const RenderListenerRef &demo, int argc, char *argv[])
std::shared_ptr< MyKeyListener > MyKeyListenerRef
int main(int argc, char *argv[])
void reshape(const WindowRef &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.
static constexpr float radius
bool init(const WindowRef &win, const jau::fraction_timespec &when) override
Called by the drawable immediately after the render context is initialized.
void dispose(const WindowRef &win, const jau::fraction_timespec &when) override
Notifies the listener to perform the release of all renderer resources per context,...
static constexpr float coreRadiusHalfStep
static constexpr float coreRadius
PMVMat4f & pmv() noexcept
void display(const WindowRef &win, const jau::fraction_timespec &when) override
Called by the drawable to initiate rendering by the client.
const Recti & viewport() const noexcept
const PMVMat4f & pmv() const noexcept
Recti & viewport() noexcept
std::string toStringImpl() const noexcept override
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_ref 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 ShaderCodeRef create(GLenum type, size_t count, const source_list_t &sources) noexcept
void destroy(GL &gl) noexcept
Detaches all shader codes and deletes the program.
static ShaderProgramRef create() noexcept
bool add(const ShaderCodeRef &shaderCode) noexcept
Adds a new shader to this program.
constexpr bool inUse() const noexcept
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
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
size_t removeKeyListener(const KeyListenerRef &l)
void dispose(const jau::fraction_timespec &when) noexcept override
std::string toString() const noexcept
void addKeyListener(const KeyListenerRef &l)
std::string toString() const noexcept
constexpr VKeyCode keySym() const noexcept
Returns the virtual key symbol reflecting the current keyboard layout.
Listener for multiple KeyEvent.
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.
std::shared_ptr< GLUniformSyncPMVMat4f > GLUniformSyncPMVMat4fRef
GLArrayDataServerRef< float > GLFloatArrayDataServerRef
std::shared_ptr< GLUniformScalarF32 > GLUniformScalarF32Ref
std::shared_ptr< GLUniformVec4f > GLUniformVec4fRef
std::shared_ptr< ShaderProgram > ShaderProgramRef
std::shared_ptr< ShaderCode > ShaderCodeRef
@ verbose
Verbose operations (debugging).
std::shared_ptr< Window > WindowRef
@ VK_ESCAPE
Constant for the ESCAPE function key.
PMVMatrix4< float > PMVMat4f
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
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.