Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 734 times)
0 Members and 1 Guest are viewing this topic.
Offline .exe

Senior Newbie





« Posted 2011-12-29 17: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 18: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 21: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!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #3 - Posted 2011-12-29 22: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-29 23: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.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (56 views)
2014-10-14 00:39:48

TehJavaDev (55 views)
2014-10-14 00:35:47

TehJavaDev (46 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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