Posted by
PedDavid on
Jun 02, 2015; 1:10am
URL: https://forum.jogamp.org/Texture-Problem-probably-gl-glTexImage2D-tp4034564.html
I'm not getting anything when rendering with the texture (black screen with a shader output = texture input and normal colors with shader that outputs simple colors(the one in the git repository)).
My method is:
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, texture.getWidth(), texture.getHeight(), 0, GL2.GL_RGB, GL2.GL_UNSIGNED_BYTE, null);
I guess that null is completely wrong...
All my loadTexture method:
public int loadTexture(String fileName){
Texture texture = new Texture(0);
try{
FileInputStream textureInput = new FileInputStream(fileName + ".png");
texture = TextureIO.newTexture(textureInput, false, null);
}catch (IOException e){
System.out.println("Failed loading texture");
e.printStackTrace();
System.exit(0);
}
gl.glGenTextures(1, tempTextureHolder, 0);
gl.glBindTexture(GL2.GL_TEXTURE_2D, tempTextureHolder[0]);
textures.add(tempTextureHolder[0]);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, texture.getWidth(), texture.getHeight(), 0, GL2.GL_RGB, GL2.GL_UNSIGNED_BYTE, null);
System.out.println("Texture : "+ gl.glIsTexture(tempTextureHolder[0])); //returning true
return tempTextureHolder[0];
}
complete code (a real mess):
https://github.com/PedDavid/NubDevEngineWould love some feedback on the code and if someone could point me in the right direction about textures
Edit: The code still hasn't the changes I made to display, textureLoader (that I already showed) and a second vbo with the textures coordinates
display is:
shader.start();
gl.glBindVertexArray(model.getVaoID());
gl.glEnableVertexAttribArray(0);
gl.glEnableVertexAttribArray(1);
gl.glActiveTexture(GL2.GL_TEXTURE0);
gl.glBindTexture(GL2.GL_TEXTURE_2D, texModel.getTexture().getId());
gl.glDrawElements(GL_TRIANGLES, model.getVertexCount(), GL_UNSIGNED_INT, 0);
gl.glDisableVertexAttribArray(0);
gl.glDisableVertexAttribArray(1);
gl.glBindVertexArray(0);
shader.stop();