Improved Binding of textures
This commit is contained in:
parent
8174ebaee4
commit
f1f076acf4
5 changed files with 27 additions and 4 deletions
|
@ -86,10 +86,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
oglu::ClearScreen(GL_COLOR_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
oglu::ClearScreen(GL_COLOR_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
||||||
|
|
||||||
oglu::ActiveTexture(0);
|
crate->BindAs(0);
|
||||||
crate->Bind();
|
opengl->BindAs(1);
|
||||||
oglu::ActiveTexture(1);
|
|
||||||
opengl->Bind();
|
|
||||||
|
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->SetUniform("texture1", 0);
|
shader->SetUniform("texture1", 0);
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
namespace oglu
|
namespace oglu
|
||||||
{
|
{
|
||||||
class Color;
|
class Color;
|
||||||
|
class AbstractTexture;
|
||||||
|
|
||||||
|
typedef std::shared_ptr<AbstractTexture> Texture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief An object representing an OpenGL Shader Program.
|
* @brief An object representing an OpenGL Shader Program.
|
||||||
|
|
|
@ -59,6 +59,16 @@ namespace oglu
|
||||||
*/
|
*/
|
||||||
void Bind();
|
void Bind();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets active texture and binds this texture.
|
||||||
|
*
|
||||||
|
* In order to use multiple textures in the same shader the active texture unit needs to be specified.
|
||||||
|
* This function first sets the active texture unit and then binds the texture.
|
||||||
|
*
|
||||||
|
* @param[in] index Index of the texture unit (Note: This index is actually an offset to @p GL_TEXTURE0)
|
||||||
|
*/
|
||||||
|
void BindAs(GLbyte index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unbind this texture.
|
* @brief Unbind this texture.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace oglu
|
||||||
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
|
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
|
||||||
std::string err = ("Failed to compile shader " + std::string(vertexShaderFile) + "\n" + infoLog);
|
std::string err = ("Failed to compile shader " + std::string(vertexShaderFile) + "\n" + infoLog);
|
||||||
delete source;
|
delete source;
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
throw std::runtime_error(err);
|
throw std::runtime_error(err);
|
||||||
}
|
}
|
||||||
delete source;
|
delete source;
|
||||||
|
@ -57,6 +58,8 @@ namespace oglu
|
||||||
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
|
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
|
||||||
std::string err = ("Failed to compile shader " + std::string(fragmentShaderFile) + "\n" + infoLog);
|
std::string err = ("Failed to compile shader " + std::string(fragmentShaderFile) + "\n" + infoLog);
|
||||||
delete source;
|
delete source;
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
throw std::runtime_error(err);
|
throw std::runtime_error(err);
|
||||||
}
|
}
|
||||||
delete source;
|
delete source;
|
||||||
|
@ -72,6 +75,9 @@ namespace oglu
|
||||||
{
|
{
|
||||||
glGetProgramInfoLog(program, 512, NULL, infoLog);
|
glGetProgramInfoLog(program, 512, NULL, infoLog);
|
||||||
std::string err = ("Failed to link program.\n" + std::string(infoLog));
|
std::string err = ("Failed to link program.\n" + std::string(infoLog));
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
|
glDeleteProgram(program);
|
||||||
throw std::runtime_error(err);
|
throw std::runtime_error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,12 @@ namespace oglu
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractTexture::BindAs(GLbyte index)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0 + index);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractTexture::Unbind()
|
void AbstractTexture::Unbind()
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue