no texture problem

Started by
3 comments, last by szalejot 13 years, 3 months ago
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?
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.
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.
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.

[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
This works. I don't know why it wasn't default value.
Guys, you are just great :-)

This topic is closed to new replies.

Advertisement