Permalink
Browse files

texture test working

  • Loading branch information...
Detegr committed Mar 22, 2013
1 parent 918e4a3 commit d6afda5db311aa7fbfd632e7824acb2341140ca4
Showing with 13 additions and 6 deletions.
  1. +4 −2 entity.cpp
  2. +2 −2 green.frag
  3. +7 −2 texture.cpp
View
@@ -25,6 +25,7 @@ C_GfxEntity* C_GfxEntity::M_Create(unsigned short id, const C_Model& m, const st
std::cout << "Loading texture " << texturepath << "...";
if(e->m_Texture.LoadData(texturepath)) std::cout << "OK!" << std::endl;
else std::cout << "failed!" << std::endl;
+ e->m_Texture.SetFiltering(GL_NEAREST);
return e;
}
@@ -100,11 +101,12 @@ void C_GfxEntity::M_Draw() const
if(m_Texture.Id())
{
GLuint texloc=glGetUniformLocation(C_Singleton::M_Renderer()->CurrentShaderId(), "texsampler");
- glUniform1i(texloc, m_Texture.Id());
+ glBindTexture(GL_TEXTURE_2D, m_Texture.Id());
+ glUniform1i(texloc, 0);
std::cout << "texloc: " << texloc << " texid: " << m_Texture.Id() << std::endl;
- GLfloat uv[5*2] = { 0.0f, 0.0f,
+ GLfloat uv[] = { 0.0f, 0.0f,
0.2f, 0.2f,
0.4f, 0.4f,
0.6f, 0.6f,
View
@@ -6,6 +6,6 @@ in vec2 uv;
void main(void)
{
- out_color = vec4(uv, 1.0, 1.0); //
- //out_color=vec4(texture2D(texsampler, uv).rgb, 1.0);
+ //out_color = vec4(uv, 1.0, 1.0); //
+ out_color=vec4(texture(texsampler, uv).rgb, 1.0);
}
View
@@ -8,13 +8,14 @@ C_Texture::C_Texture() : m_Id(0), m_Data(0), m_Width(0), m_Height(0)
C_Texture::C_Texture(unsigned int w, unsigned int h) : m_Id(0), m_Data(NULL), m_Width(w), m_Height(h)
{
glGenTextures(1, &m_Id);
- glBindTexture(GL_TEXTURE_2D, m_Id);
}
void C_Texture::SetData(const GLvoid* data)
{
+ glBindTexture(GL_TEXTURE_2D, m_Id);
m_Data=data;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_Width, m_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_Data);
+ glBindTexture(GL_TEXTURE_2D, 0);
}
bool C_Texture::LoadData(const std::string& path)
@@ -24,13 +25,17 @@ bool C_Texture::LoadData(const std::string& path)
glGenTextures(1, &m_Id);
glBindTexture(GL_TEXTURE_2D, m_Id);
}
- return glfwLoadTexture2D(path.c_str(), 0);
+ bool ret=glfwLoadTexture2D(path.c_str(), 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ return ret;
}
void C_Texture::SetFiltering(GLfloat f)
{
+ glBindTexture(GL_TEXTURE_2D, m_Id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, f);
+ glBindTexture(GL_TEXTURE_2D, 0);
}
GLuint C_Texture::Id() const

0 comments on commit d6afda5

Please sign in to comment.