Simple solar fragment-shader w/ core- and halo-radius.
Simple solar fragment-shader w/ core- and halo-radius.
#include <cstdio>
#include <cmath>
#include <memory>
#include "../demos/GLLauncher01.hpp"
public:
static constexpr float radius = 1.00f;
private:
bool m_initialized;
public:
if (win) {
}
}
}
}
};
public:
m_initialized(false),
m_kl(std::make_shared<MyKeyListener>(*this))
{ }
PMVMat4f&
pmv()
noexcept {
return m_pmvMatUni->pmv(); }
const PMVMat4f&
pmv()
const noexcept {
return m_pmvMatUni->pmv(); }
m_tlast = when;
"demos/glsl/bin", "default");
"demos/glsl/bin", "SolInSpace");
if( !vp0 || !fp0 ) {
win->dispose(when);
return false;
}
vp0->defaultShaderCustomization(
gl);
fp0->defaultShaderCustomization(
gl);
if( !sp0->add(
gl, vp0,
true) || !sp0->add(
gl, fp0,
true) ) {
win->dispose(when);
return false;
}
::glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
m_uBackColor->vec4f().set(0.0f, 0.0f, 0.0f, 0.5f);
vertices->reserve(4);
vertices->seal(
gl,
true);
::glEnable(GL_DEPTH_TEST);
m_initialized = sp0->inUse();
if( !m_initialized ) {
win->dispose(when);
}
win->addKeyListener(m_kl);
return m_initialized;
}
win->removeKeyListener(m_kl);
m_initialized = false;
}
const float aspect = 1.0f;
const float fovy_deg=45.0f;
const float aspect2 = ( (float) m_viewport.
width() / (
float) m_viewport.
height() ) / aspect;
const float zNear=1.0f;
const float zFar=100.0f;
}
if( !m_initialized ) {
return;
}
::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
{
const Vec3f center(0,0,0);
m_uWinCenter->vec4f().set(winCenter, 1.0f);
Vec3f winR = winP1 - winCenter;
m_uWinRadius->scalar() = winR.
length();
static float dr_dir = 1;
const float dt = (float)(when - m_tlast).to_ms() / 1000.0f;
if( r <= dr_min ) {
dr_dir = 1;
r = dr_min;
} else if( r >= dr_max ) {
dr_dir = -1;
r = dr_max;
}
m_uCoreRadius->scalar() = r;
}
std::cerr << "XXX: " << m_st << "\n";
}
if( true ) {
::glEnable(GL_BLEND);
::glBlendEquation(GL_FUNC_ADD);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
::glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
m_tlast = when;
}
std::string
toStringImpl()
const noexcept override {
return "SolInSpace"; }
};
int main(
int argc,
char *argv[])
{
std::make_shared<Example>(), argc, argv);
}
int launch(std::string_view sfile, GLLaunchProps props, const RenderListenerRef &demo, int argc, char *argv[])
int main(int argc, char *argv[])
std::shared_ptr< MyKeyListener > MyKeyListenerRef
static constexpr float radius
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.
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)
static ShaderCodeRef create(GLenum type, size_t count, const source_list_t &sources) noexcept
static ShaderProgramRef create() noexcept
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
bool pushUniform(const GL &gl, const GLUniformDataRef &data)
Set the uniform data, if it's location is valid, i.e.
void destroy(GL &gl)
Calls release(gl, true, true, true).
void ownUniform(const GLUniformDataRef &data, bool own)
Bind the GLUniform lifecycle to this ShaderState.
void useProgram(GL &gl, bool on)
Turns the shader program on or off.
void pushAllUniforms(const GL &gl)
Same as pushUniform(), but for all active uniforms.
void ownAttribute(const GLArrayDataRef &attr, bool own)
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
bool attachShaderProgram(GL &gl, const ShaderProgramRef &prog, bool enable)
Attach or switch a shader program.
constexpr RenderListener(Private) noexcept
Private ctor for shared_ptr<RenderListener> instance method w/o public ctor.
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 Matrix4 & loadIdentity() noexcept
Set this matrix to identity.
constexpr value_type height() const noexcept
constexpr value_type width() const noexcept
constexpr value_type length() const noexcept
Return the length of a vector, a.k.a the norm or magnitude
constexpr Mat4 & getP() noexcept
Returns the projection matrix (P).
constexpr PMVMatrix4 & translateMv(float x, float y, float z) noexcept
Translate the modelview matrix.
PMVMatrix4 & setToPerspective(const float fovy_rad, const float aspect, const float zNear, const float zFar)
Set the projection matrix to the perspective/frustum matrix.
constexpr Mat4 & getMv() noexcept
Returns the modelview matrix (Mv).
bool mapObjToWin(const Vec3 &objPos, const Recti &viewport, Vec3 &winPos) const noexcept
Map object coordinates to window coordinates.
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.