Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Texturing problem  (Read 493 times)
0 Members and 1 Guest are viewing this topic.
Offline .exe

Senior Newbie





« Posted 2011-12-29 18:06:35 »

I am trying to bake texture in 3DS Max and use it in OpenGL, but texture looks weird.
I was looking on google for few hours, but cant find any solution.  Sad


Here is my code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
public void RenderObject(CObject obj)
   {
      CMesh m; MFace f; MVertex v; MNormal n; MTexCords t; CTexture tx;
     
      tx = obj.GetTexture(); m = obj.GetMesh();
     
      if(tx.hasTexture())
      {
         tx.apply2Object(gl.getGL());
      }
     
      gl.glTranslatef(obj.location.x, obj.location.y, obj.location.z);
      gl.glRotatef(obj.rotation.x, 1, 0, 0);
      gl.glRotatef(obj.rotation.y, 0, 1, 0);
      gl.glRotatef(obj.rotation.z, 0, 0, 1);
     
      for(int i = 0; i < m.getFaceList().size();i++)
      {
         f = m.getFaceList().get(i);
         
         gl.glColor3f(0.5f, 0.5f, 0.5f);
         gl.glBegin(GL2.GL_POLYGON);
               
         for(int j = 0;j < f.GetPolygonCount();j++)
         {
            v = m.getVertexList().get(f.GetPolygonByIndex(j).vertexIndex - 1);
            t = m.getTexCordsList().get(f.GetPolygonByIndex(j).texcordIndex - 1);
            n = m.getNormalList().get(f.GetPolygonByIndex(j).normalIndex - 1);
           
            gl.glNormal3f(n.x, n.y, n.z);
            gl.glTexCoord3f(t.u,t.v, t.w);
            gl.glVertex3f(v.x, v.y, v.z);
           
         }

         gl.glEnd();
      }


Code is based on open source OBJ loader in c++.
http://sourceforge.net/projects/objloader/

What i want:
http://img521.imageshack.us/img521/5181/wantp.jpg

What i get:
http://img171.imageshack.us/img171/645/getor.jpg

Baked texture:
http://img205.imageshack.us/img205/8562/bakedi.jpg


help!?
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2011-12-29 19:25:56 »

It looks like your texture coordinates are not being loaded correctly.  I would print out or debug the texture coordinates that were loaded in to make sure you're passing in the expected values.  You could try testing a simpler model, such as a textured cube to see if there are problems with your RenderObject() or your parser.

A couple of other suggestions:
1. Subtract 1 from the polygon indices in the parser, so you don't have to remember to do it every time you need to access the vertex, normal or texcoords lists.
2. In MFace, you have getPolygonCount() and getPolygonByIndex() but the MFace is the polygon and those methods appear to return the vertex count and vertex information.  If that's not what they are doing, then you should look carefully at your RenderObject() method.

Offline .exe

Senior Newbie





« Reply #2 - Posted 2011-12-29 22:21:37 »

some things are complicated too much, somewhere used wrong names...
but anyway i have checked parsed data, everything is correct.

tested with simple object, result:
http://img7.imageshack.us/img7/5130/omgwtfqj.jpg

looks like texture is applied on every side, instead of whole object.

here is my CTexture class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public class CTexture 
{
   private Texture texture;
   private boolean loaded;
   
   public CTexture()
   {
      loaded = false;
   }
   
   public void LoadTextureFromResource(String res,String type) throws IOException
   {
        InputStream stream = getClass().getResourceAsStream(res);
        TextureData data = TextureIO.newTextureData(GLProfile.getDefault(),stream, false, type);
        this.texture = TextureIO.newTexture(data);
        this.loaded = true;
   }
   
   public boolean hasTexture()
   {
      return loaded;
   }
   
   public void apply2Object(GL gl)
   {
      texture.enable(gl);
      texture.bind(gl);
   }
   
}




Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline lhkbob

JGO Knight


Medals: 32



« Reply #3 - Posted 2011-12-29 23:47:06 »

Well in the cube example, it might be that the correct texture coordinates would display the entire image on each cube face.

Try experimenting in the cube obj file and change the 1's in the texture coordinates to 0.5's.  This should then display the bottom quarter of the image stretched over each face.

Offline .exe

Senior Newbie





« Reply #4 - Posted 2011-12-30 00:16:49 »

texture coords were wrong,
i needed to use UVW Unwrap modifier in 3DS max.

after that works perfectly Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (67 views)
2013-05-17 21:29:12

alaslipknot (76 views)
2013-05-16 21:24:48

gouessej (109 views)
2013-05-16 00:53:38

gouessej (104 views)
2013-05-16 00:17:58

theagentd (115 views)
2013-05-15 15:01:13

theagentd (104 views)
2013-05-15 15:00:54

StreetDoggy (149 views)
2013-05-14 15:56:26

kutucuk (172 views)
2013-05-12 17:10:36

kutucuk (170 views)
2013-05-12 15:36:09

UnluckyDevil (179 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.176 seconds with 21 queries.