LWJGL - Rendering A Texture Onto A VBO >>($10 REWARD)<<

Ok, so i can imagine I may get a little telling off for a reupload but its quite important that I get this bug sorted as I dont know what Im doing wrong. Im not going to give you an essay but whats happening is that the texture is not rendering correctly for some reason and I need help! Here is the simplified code from the project:

ADDITIONAL: I know the texture and model along with UVs work correctly as I tested them with a displaylist(the old way I used to do things…)

SOURCE CODE:
http://pastebin.java-gaming.org/13c392a579f

I might have missed it but did you call glEnable(GL_TEXTURE_2D) anywhere?

Yeh Im pretty sure i did, I’ll check soon!
Its weird though cos the texture draws but its like it draws it in the wrong place.

Then double check your UV maps :wink: I’m sorry but I’m a newbie to opengl myself and that’s the only thing that comes to my head.

Does glGetError() return anything?

I looked and yes glEnable(GL_TEXURE2D) is in and I shall glGetError()

Try inverting the UV on the Y axis, OpenGL is weird that way.
If you’ve already done that, then I don’t know.

How would I go about doing that, code sample?

Thanks for all the answers btw, your all what makes this forum gre

Can you post a screenshot what’s happening? It would make the problem a lot easier to solve.

In my case, not sure if it’s the best way to go about it, but I just multiplied the Y value by -1.

This is a snippet from a class that parses the data from a file and puts the data into arrays, after, it sorts them out.

// Check if current line starts with vt (I'm importing from a file that is in the Wavefront format)
else if(line.startsWith("vt ")) {
// Find where in the line the values start and end and then loop through 
	for(int i = parse.getStartIndex(), j = 0; i <= parse.getEndIndex(); i++, j++) {
		if(j == 0) {
// Get the value at point in string, and set the value to the corresponding place in the UV array (cUv)
			getUv()[cUv] = Float.valueOf(line.split(" ")[i]);
			cUv++;
		} else {
// Same again but invert the Y axis by multiplying its value.
			getUv()[cUv] = Float.valueOf(line.split(" ")[i]) * -1;
			cUv++;
		}
	}
}

This is what the model and the texture look like with displayLists:
Imgur

And this is what it looks like now:
Imgur

Full project for eclipse if your genourous enough to look and run the program:

For inverting the UV on the Y axis would you do 1-yComponent? Although I think I get it how multiplying by -1 would have the same result.

Looks like UV problem, but why is the model red?

EDIT:
After a quick look at your project, I’d suggest you rewrite OBJLoader. You either create the VBOs in OBJLoader or in the Game, not both. It’s confusing because I don’t know which one you’re using, not to mention the OBJLoader doesn’t create the buffer for UVs.

You may want to look at how you’re loading and creating the buffer for the UVs in the Game class, especially


FloatBuffer UVs = reserveData(m.faces.size() * 9);

Make sure you’re only reading 2 values per vertex, not 3. So I guess it should be


FloatBuffer UVs = reserveData(m.faces.size() * 6);

It’s only a speculation and I don’t know if this will fix the problem

PS. you don’t need to include every single jar file in your class path :wink:

Thanks man for the attempt anyway its helped anyway, I’ll look at what you said and the models red because the color is set to red, sorry i forgot to mention it! :slight_smile:

I tried changin the value to 6, 8, and 4 and it didnt work…
I also looked at the OBJLoader and deleted VBO material that I forgot was there but still no differance, I dont even know where to look next…

Does anyone have a project with textured VBOs that I can snatch up

One thing I have realise when changing the model is that the texture is strech for a polygon and normal for another, you can check if you change the model and texture to floor.png and floor.obj in the project at the start of the thread. For lazy people ;D it looks like so:

Imgur
(The top left poly is the normal texture, the bottom right is the stretched rest)

I’ve never textured a model in VBO before but I’ll try to look into it. From the looks of the picture I think the second polygon’s UVs are are broken :clue:

You are setting up your texture coord pointer wrong.


glTexCoordPointer(3, GL_FLOAT, 0, 0);

You are saying it that you have three components, whereas there are only two. This should fix it.


glTexCoordPointer(2, GL_FLOAT, 0, 0);

Hope this helps.

Im sure it say 2 and not 3 already, I’ll check again tomorrow! Thanks!

Yes I spotted this one, but in the project files he uploaded it’s been fixed

To avoid confusion, please post only relevant portions of code and always, post them to the pastebin.

Okay, I have downloaded the project files for you and had a quick gander at the files. Here are my observations.

[icode]Game.java#L114[/icode]


-    FloatBuffer UVs = reserveData(m.faces.size() * 9);
+    FloatBuffer UVs = reserveData(m.faces.size() * 6);

This one just reduces the extra unused memory in the FloatBuffer.

[icode]Game.java#L153[/icode]


-    glColor3f(0.90f, 0.27f, 0.17f);

This line is what is causing the red color on your model. Remove it and you will see it in the default white color.

Next, my main observation is that I can’t find any place where you bind your texture. Place this in the render method.


+    m.texture.bind();

These are my observations for now, I’ll keep looking for more.