Jump to content
  • Advertisement
Sign in to follow this  
szalejot

OpenGL no texture problem

This topic is 2912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm new to OpenGL.
I want to have textures, but I think I'm doing something wrong.

My initiation

public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glEnable(GL.GL_CULL_FACE);
gl.setSwapInterval(1);
drawable.addKeyListener(this);
drawable.addKeyListener(thread);

gl.glEnable(GL.GL_NORMALIZE);
gl.glEnable(GL.GL_COLOR_MATERIAL);

loadTextures();
}




Loading texture:

private void loadTextures(){
try{
InputStream stream = getClass().getResourceAsStream("bricks.png");
TextureData data = TextureIO.newTextureData(stream, false, "png");
wallTexture = TextureIO.newTexture(data);
}
catch (IOException ex){
ex.printStackTrace();
System.exit(1);
}
}




and drawing the wall (code for one, others almost the same)

private void addWalls(GL gl, float x, float z, int dir){
gl.glPushMatrix();
gl.glBegin(GL.GL_QUADS);
wallTexture.enable();
wallTexture.bind();
gl.glNormal3f(-1.0f, 0.0f, 0.0f);
gl.glTexCoord2f(0, 0);
gl.glVertex3f(x, 0.0f, z+1);
gl.glTexCoord2f(1, 0);
gl.glVertex3f(x, 1.0f, z+1);
gl.glTexCoord2f(1, 1);
gl.glVertex3f(x, 1.0f, z);
gl.glTexCoord2f(0, 1);
gl.glVertex3f(x, 0.0f, z);
(...)//other walls
wallTexture.disable();
gl.glEnd();
gl.glPopMatrix();
}




wallTexture is opengl.util.texture.Texture
When I run it walls aren't textured, they are just white.
What I am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
You can't call bind texture between glBegin() and glEnd() pairs. Try moving the

wallTexture.enable();
wallTexture.bind();



To before the glBegin();

I haven't read through the rest of your code, but that looks to be the most obvious mistake to me at the moment.

Share this post


Link to post
Share on other sites
Thanks, that fixes this problem :-)

I have another problem. I want to texture the wall (I have bricks texture). Wall is one quad and I want to "have" this texture few times. I tried with TexCoord greater than 1, but it only multiplies boundary pixels, not whole texture.
It have to be easy way to achieve that, but I don't know how ask uncle google properly.

Share this post


Link to post
Share on other sites
You should be able to use texcoords greater than one and have the texture repeat.

you need to use glTexParameteri to set the GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_REPEAT. However GL_REPEAT should be the default value for these, so I'm not sure why your texture would be clamping the edge if you haven't changed it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!