Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  LWJGL - Rendering A Texture Onto A VBO >>($10 REWARD)<<  (Read 2972 times)
0 Members and 1 Guest are viewing this topic.
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Posted 2014-06-05 10:22:09 »

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 love making games...
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #1 - Posted 2014-06-05 14:19:31 »

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

Junior Member


Medals: 1
Exp: 4 years



« Reply #2 - Posted 2014-06-05 17:56:03 »

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.

I love making games...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #3 - Posted 2014-06-05 20:06:16 »

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.
Offline NegativeZero

JGO Knight


Medals: 30
Projects: 2
Exp: 3 years


Zero but not.


« Reply #4 - Posted 2014-06-05 20:12:41 »

Does glGetError() return anything?
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #5 - Posted 2014-06-05 20:50:20 »

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

I love making games...
Offline bogieman987
« Reply #6 - Posted 2014-06-05 20:55:47 »

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

Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #7 - Posted 2014-06-05 21:21:15 »

How would I go about doing that, code sample?

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

I love making games...
Offline NegativeZero

JGO Knight


Medals: 30
Projects: 2
Exp: 3 years


Zero but not.


« Reply #8 - Posted 2014-06-05 21:25:34 »

Can you post a screenshot what's happening? It would make the problem a lot easier to solve.
Offline bogieman987
« Reply #9 - Posted 2014-06-05 21:46:39 »

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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
// 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++;
      }
   }
}

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #10 - Posted 2014-06-06 09:56:38 »

This is what the model and the texture look like with displayLists:
http://imgur.com/I7zGJmR


And this is what it looks like now:
http://imgur.com/juCAl6B


Full project for eclipse if your genourous enough to look and run the program:
https://www.dropbox.com/s/7yb5zg1dmf10voa/VRAID%20WITH%20VBOs%20AND%20TEXT.rar

I love making games...
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #11 - Posted 2014-06-06 11:58:22 »

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. </offtopic>

You may want to look at how you're loading and creating the buffer for the UVs in the Game class, especially
1  
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
1  
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
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #12 - Posted 2014-06-06 19:46:59 »

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! Smiley

I love making games...
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #13 - Posted 2014-06-07 09:12:09 »

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

I love making games...
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #14 - Posted 2014-06-07 16:10:05 »

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  Grin it looks like so:


http://imgur.com/GRywvgM
(The top left poly is the normal texture, the bottom right is the stretched rest)

I love making games...
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #15 - Posted 2014-06-07 16:34:48 »

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 Clueless
Offline SHC
« Reply #16 - Posted 2014-06-07 18:51:42 »

You are setting up your texture coord pointer wrong.

1  
glTexCoordPointer(3, GL_FLOAT, 0, 0);

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

1  
glTexCoordPointer(2, GL_FLOAT, 0, 0);

Hope this helps.

Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #17 - Posted 2014-06-07 19:56:53 »

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

I love making games...
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #18 - Posted 2014-06-07 21:15:54 »

Yes I spotted this one, but in the project files he uploaded it's been fixed
Offline SHC
« Reply #19 - Posted 2014-06-08 02:05:23 »

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.

Game.java#L114

1  
2  
-    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.

Game.java#L153

1  
-    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.

1  
+    m.texture.bind();

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

Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #20 - Posted 2014-06-08 06:46:54 »

Wow thanks man, good observations, ill fix the code later and see what happens!
Thanks everyone for trying to help Smiley

I love making games...
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #21 - Posted 2014-06-08 09:03:42 »

Its weird its like half of the texture is stretched and the other half is fine, so it must be an error to do with that, because the texture itself is actually being drawn!

Here, it shows the normal texture in the bottom to top left triangle whereas its like its been stretched across for the one the right...
http://imgur.com/awJpSGL

Also, the new project files:
https://www.dropbox.com/s/7yb5zg1dmf10voa/VRAID%20WITH%20VBOs%20AND%20TEXT.rar

I love making games...
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #22 - Posted 2014-06-09 09:27:44 »

Start by texturing a VBO quad manually, then a cube. After that, export a quad from blender or whatever you use and write your code from scratch. Make it as simple as possible. When you succeed, only then go on and implement it in your project Cheesy
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #23 - Posted 2014-06-09 11:20:43 »

I know how they work so this would be pointless man Grin
If you have so much knowledge on the subject I would love to see if you could fix the problem here Grin Grin...

I love making games...
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #24 - Posted 2014-06-09 12:39:31 »

Haha, the problem is I -don't- have the knowledge Lips Sealed I'll have a go, but I don't know when I'll have free time Clueless
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #25 - Posted 2014-06-09 12:40:25 »

Thanks man, thats the spirit!  Cheesy Smiley Smiley

I love making games...
Offline CHmSID

Senior Newbie


Exp: 7-9 months



« Reply #26 - Posted 2014-06-09 12:47:54 »

Eh, you make it sound like I'm doing work for you...
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #27 - Posted 2014-06-09 13:00:46 »

Haha. No, your just being a nice gentlemen by helping out a fellow JGOer

I love making games...
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #28 - Posted 2014-06-10 07:19:23 »

Any one figured it out yet, theres $5 up for grabs!

I love making games...
Offline trollwarrior1
« Reply #29 - Posted 2014-06-10 07:51:45 »

So did you change UV component amount to 2 instead of 3?

In the code in the first post, you tell opengl that your UVs are of 3 components, but you put only 2.

From this:
1  
glTexCoordPointer(3, GL_FLOAT, 0, 0)

To this:
1  
glTexCoordPointer(2, GL_FLOAT, 0, 0)
Pages: [1] 2
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (10 views)
2014-10-02 14:36:20

Pippogeek (41 views)
2014-09-24 16:13:29

Pippogeek (32 views)
2014-09-24 16:12:22

Pippogeek (22 views)
2014-09-24 16:12:06

Grunnt (48 views)
2014-09-23 14:38:19

radar3301 (30 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!