Skip to content

Commit

Permalink
Fixed keys for SLUniform variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm4 committed Oct 5, 2024
1 parent f958fbb commit f331d52
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 46 deletions.
17 changes: 4 additions & 13 deletions apps/app_demo/source/scenes/AppDemoSceneShaderBump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
AppDemoSceneShaderBump::AppDemoSceneShaderBump()
: SLScene("Normal Map Bump Mapping")
{
info("Normal map bump mapping combined with a spot and a directional lighting.");
info("Normal map bump mapping combined with a spot lighting.");
}
//-----------------------------------------------------------------------------
//! All assets the should be loaded in parallel must be registered in here.
void AppDemoSceneShaderBump::registerAssetsToLoad(SLAssetLoader& al)
{
al.addTextureToLoad(_texC,
AppCommon::texturePath +
"brickwall0512_C.jpg");
"brickwall0512_C.jpg");
al.addTextureToLoad(_texN,
AppCommon::texturePath +
"brickwall0512_N.jpg");
"brickwall0512_N.jpg");
}
//-----------------------------------------------------------------------------
//! After parallel loading of the assets the scene gets assembled in here.
Expand All @@ -58,26 +58,17 @@ void AppDemoSceneShaderBump::assemble(SLAssetManager* am, SLSceneView* sv)
light1->translation(0, 0, 5);
light1->lookAt(0, 0, 0);

SLLightDirect* light2 = new SLLightDirect(am, this);
light2->ambientColor(SLCol4f(0, 0, 0));
light2->diffuseColor(SLCol4f(1, 1, 0));
light2->specularColor(SLCol4f(1, 1, 0));
light2->translation(-5, -5, 5);
light2->lookAt(0, 0, 0);
light2->attenuation(1, 0, 0);

SLAnimation* anim = this->animManager().createNodeAnimation("light1_anim",
2.0f);
anim->createNodeAnimTrackForEllipse(light1,
2.0f,
A_x,
2.0f,
A_Y);
A_y);

SLNode* scene = new SLNode;
this->root3D(scene);
scene->addChild(light1);
scene->addChild(light2);
scene->addChild(new SLNode(new SLRectangle(am,
SLVec2f(-5, -5),
SLVec2f(5, 5),
Expand Down
8 changes: 4 additions & 4 deletions apps/app_demo/source/scenes/AppDemoSceneShaderEarth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ AppDemoSceneShaderEarth::AppDemoSceneShaderEarth()
{
info("Complex earth shader with 7 textures: day color, night color, "
"normal, height & gloss map of earth, color & alpha-map of clouds.\n"
"Use (SHIFT) & key X to change scale of the parallax mapping\n"
"Use (SHIFT) & key O to change offset of the parallax mapping");
"Use (SHIFT) & key F2 to change scale of the parallax mapping\n"
"Use (SHIFT) & key F3 to change offset of the parallax mapping");
}
//-----------------------------------------------------------------------------
//! All assets the should be loaded in parallel must be registered in here.
Expand Down Expand Up @@ -61,14 +61,14 @@ void AppDemoSceneShaderEarth::assemble(SLAssetManager* am, SLSceneView* sv)
0.002f,
0,
1,
(SLKey)'X');
(SLKey)K_F2);
SLGLUniform1f* offset = new SLGLUniform1f(UT_const,
"u_offset",
-0.02f,
0.002f,
-1,
1,
(SLKey)'O');
(SLKey)K_F3);
this->eventHandlers().push_back(scale);
this->eventHandlers().push_back(offset);
_sp->addUniform1f(scale);
Expand Down
21 changes: 6 additions & 15 deletions apps/app_demo/source/scenes/AppDemoSceneShaderParallax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
AppDemoSceneShaderParallax::AppDemoSceneShaderParallax()
: SLScene("Parallax Bump Mapping Test")
{
info("Normal map parallax mapping with a spot and a directional light"
"Use X-Key to increment (decrement w. shift) parallax scale."
"Use O-Key to increment (decrement w. shift) parallax offset.\n");
info("Parallax mapping with a spot. "
"Use F2-Key to increment (decrement w. shift) parallax scale."
"Use F3-Key to increment (decrement w. shift) parallax offset.\n");
}
//-----------------------------------------------------------------------------
//! All assets the should be loaded in parallel must be registered in here.
Expand All @@ -49,14 +49,14 @@ void AppDemoSceneShaderParallax::assemble(SLAssetManager* am, SLSceneView* sv)
0.002f,
0,
1,
(SLKey)'X');
(SLKey)K_F2);
SLGLUniform1f* offset = new SLGLUniform1f(UT_const,
"u_offset",
-0.03f,
0.002f,
-1,
1,
(SLKey)'O');
(SLKey)K_F3);
this->eventHandlers().push_back(scale);
this->eventHandlers().push_back(offset);
_sp->addUniform1f(scale);
Expand Down Expand Up @@ -88,25 +88,16 @@ void AppDemoSceneShaderParallax::assemble(SLAssetManager* am, SLSceneView* sv)
light1->translation(0, 0, 5);
light1->lookAt(0, 0, 0);

SLLightDirect* light2 = new SLLightDirect(am, this);
light2->ambientColor(SLCol4f(0, 0, 0));
light2->diffuseColor(SLCol4f(1, 1, 0));
light2->specularColor(SLCol4f(1, 1, 0));
light2->translation(-5, -5, 5);
light2->lookAt(0, 0, 0);
light2->attenuation(1, 0, 0);

SLAnimation* anim = this->animManager().createNodeAnimation("light1_anim", 2.0f);
anim->createNodeAnimTrackForEllipse(light1,
2.0f,
A_x,
2.0f,
A_Y);
A_y);

SLNode* scene = new SLNode;
this->root3D(scene);
scene->addChild(light1);
scene->addChild(light2);
scene->addChild(new SLNode(new SLRectangle(am,
SLVec2f(-5, -5),
SLVec2f(5, 5),
Expand Down
4 changes: 2 additions & 2 deletions apps/app_demo/source/scenes/AppDemoSceneShaderWave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AppDemoSceneShaderWave::AppDemoSceneShaderWave()
{

info("Vertex Shader with wave displacement. "
"Use H-Key to increment (decrement w. shift) the wave height.");
"Use F2-Key to increment (decrement w. shift) the wave height.");
}
//-----------------------------------------------------------------------------
//! All assets the should be loaded in parallel must be registered in here.
Expand Down Expand Up @@ -52,7 +52,7 @@ void AppDemoSceneShaderWave::assemble(SLAssetManager* am, SLSceneView* sv)
0.05f,
0.0f,
0.5f,
(SLKey)'H');
(SLKey)K_F2);
this->eventHandlers().push_back(u_h);
_sp->addUniform1f(u_h);
_sp->addUniform1f(new SLGLUniform1f(UT_inc, "u_t", 0.0f, 0.06f));
Expand Down
8 changes: 4 additions & 4 deletions apps/app_demo/source/scenes/AppDemoSceneTextureFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ void AppDemoSceneTextureFilter::registerAssetsToLoad(SLAssetLoader& al)
al.addTextureToLoad(_texB,
AppCommon::texturePath +
"brick0512_C.png",
GL_LINEAR,
GL_LINEAR);
GL_NEAREST,
GL_NEAREST);
al.addTextureToLoad(_texL,
AppCommon::texturePath +
"brick0512_C.png",
GL_NEAREST,
GL_NEAREST);
GL_LINEAR,
GL_LINEAR);
al.addTextureToLoad(_texT,
AppCommon::texturePath +
"brick0512_C.png",
Expand Down
9 changes: 5 additions & 4 deletions apps/exercises/glUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ GLuint glUtils::buildTexture(string textureFile,
// check max. size
GLint maxSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
std::cout << "SLGLTexture::build: Max. texture size: " << maxSize << std::endl;
if (img.width() > (GLuint)maxSize || img.height() > (GLuint)maxSize)
{
std::cout << "SLGLTexture::build: Texture height is too big." << std::endl;
Expand All @@ -435,13 +436,13 @@ GLuint glUtils::buildTexture(string textureFile,

// Copy image data to the GPU. The image can be delete afterwards
glTexImage2D(GL_TEXTURE_2D, // target texture type 1D, 2D or 3D
0, // Base level for mipmapped textures
img.format(), // internal format: e.g. GL_RGBA, see spec.
(GLsizei)img.width(), // image width
0, // Base level for mipmapped textures
img.format(), // internal format: e.g. GL_RGBA, see spec.
(GLsizei)img.width(), // image width
(GLsizei)img.height(), // image height
0, // border pixels: must be 0
img.format(), // data format: e.g. GL_RGBA, see spec.
GL_UNSIGNED_BYTE, // data type
GL_UNSIGNED_BYTE, // data type
(GLvoid*)img.data()); // image data pointer

// generate the mipmap levels
Expand Down
2 changes: 1 addition & 1 deletion modules/sl/source/SLEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ enum SLRenderType
enum SLAxis
{
A_x = 0,
A_Y = 1,
A_y = 1,
A_z = 2
};
//-----------------------------------------------------------------------------
Expand Down
19 changes: 16 additions & 3 deletions modules/sl/source/gl/SLGLUniform.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ template<class T>
class SLGLUniform : public SLEventHandler
{
public:
/**
* @brief Constructs a custom uniform variable
* @param type Type of uniform variable
* @param name Name of uniform variable
* @param value Current value
* @param inc Increment value
* @param min Minimal value
* @param max Maximal value
* @param keyInc Key F1-F10 to increment the value decrement with SHIFT key
*/
SLGLUniform(SLUniformType type,
const SLchar* name,
T value,
Expand All @@ -38,6 +48,9 @@ class SLGLUniform : public SLEventHandler
_inc = inc;
_type = type;
_keyInc = keyInc;

if (_keyInc != K_none && !(_keyInc >= K_F1 && _keyInc <= K_F10))
SL_EXIT_MSG("Please use keys F1-F10 for uniform variables.");
}

SLGLUniform(const SLchar* name,
Expand Down Expand Up @@ -111,13 +124,13 @@ class SLGLUniform : public SLEventHandler
if (_value < _max)
{
_value += _inc;
// std::cout << "Uniform: " << _name.c_str() << " = " << _value << std::endl;
SL_LOG("Uniform: %s = %5.4f", _name.c_str(),(float)_value);
return true;
}
else if (_inc == _max) // Toggle between min & max
{
_value = _min;
// std::cout << "Uniform: " << _name.c_str() << " = " << _value << std::endl;
SL_LOG("Uniform: %s = %5.4f", _name.c_str(),(float)_value);
return true;
}
}
Expand All @@ -126,7 +139,7 @@ class SLGLUniform : public SLEventHandler
if (_value > _min)
{
_value -= _inc;
// std::cout << "Uniform: " << _name.c_str() << " = " << _value << std::endl;
SL_LOG("Uniform: %s = %5.4f", _name.c_str(),(float)_value);
return true;
}
}
Expand Down

0 comments on commit f331d52

Please sign in to comment.