Texture not showing up.

Started by bgilb, January 14, 2005, 03:29:28 AM

Previous topic - Next topic

bgilb

It could be a uv problem, im not sure but basically all i did was created my texturemanager, loaded a texture, applied it to a object and then called recreateTextureCoords(), in wireframe i can see that the polygons are still there. as soon as i switch back to textured mode theres nothing there.. and it does load the file im sure

some code:


                               Texture tex=new Texture("grass.jpg");
                     texMan.addTexture("base", tex);
cube = new Object3D(4);
setupMap(); // adds polys to the cube mesh
cube.setTexture("base");
cube.recreateTextureCoords();
theWorld.addObject(cube);

rolz

You have to adjust your setupMap() method to assign UV coordinates correctly.


   /**
    * adds plane to the specified object
    *
    * @param target actor to update
    * @param c1     4 coordinate points, CCW
    * @param c2
    * @param c3
    * @param c4
    */
   private static void addPlane(Object3D target, SimpleVector c1, SimpleVector c2, SimpleVector c3,
                                SimpleVector c4, float cellSize) {
       SimpleVector xVct = new SimpleVector(c1.calcSub(c2));
       SimpleVector yVct = new SimpleVector(c3.calcSub(c2));

       float x = xVct.length();
       float y = yVct.length();

       float xCoeff = x / cellSize;
       float yCoeff = y / cellSize;
       target.addTriangle(c2, 0, 0, c3, 0, yCoeff, c1, xCoeff, 0, 0, 0);
       target.addTriangle(c3, 0, yCoeff, c4, xCoeff, yCoeff, c1, xCoeff, 0, 0, 0);
   }
Regards,
Andrei

Anonymous

Thank you, I think i got it now. I am trying to make a 3d Tile engine :D

1 last question: Whats the best way to handle the 3d Tile engine? a new texture for each tile or something else like, loading all the tiles with grass, applying it, then drawing all the tiles that have sand and applying that one.
Only problem with this one is that the tiles can't really share vertices.

bgilb

woops sorry didnt login, okay i got HALF the quad textured( |\| only top right shows up), but now im not sure how to fix it, heres what my code looks like:

EDIT: Problem discovered! after much looking i figured out that one of the triangles was being draw REVERESED ( didnt think this mattered at first )so for the first addTriangle reversing the order to 1,2,3 and uv will properly fix it :D, also, still not sure how to tile the quads properly :D

Edit2: Im guessing jPCT doesn't support vertex alpha? :-(


public void setupMap()
{
//addTriangle(SimpleVector vert1, float u, float v
//, SimpleVector vert2, float u2, float v2
//, SimpleVector vert3, float u3, float v3)
SimpleVector v1 = new SimpleVector(-5f,-5f,10f);//top left
SimpleVector v2 = new SimpleVector(-5f,5f,10f);//top right
SimpleVector v3 = new SimpleVector(5f,5f,10f);//bot right
SimpleVector v4 = new SimpleVector(5f,-5f,10f);//bot left
cube.addTriangle(v3,1f,1f,
v2,-1f,1f,
v1,-1f,-1f);
cube.addTriangle(v4,1f,-1f,
v1,-1f,-1f,
v3,1f,1f);
}


Sorry about messiness, basically i indented it to show 1st line = vector,u,v and so on for the addTriangle

bgilb

Does jPCT not support grids of vertexs? im trying to first create the grid of vertexs, then fill that up with quads..

public static void setupMap(int mapSize,Object3D myObj)
{
SimpleVector[][] vertGrid = null;
float texScale = 0.8f;
int counter=0;
for(int n = 0;n<=(mapSize-1);n++)
{
for(int l=0;l<=(mapSize-1);l++)
{
float x = n*2;
float y = l*2;
vertGrid[n][l] = new SimpleVector((x),(y),1f);
}
}

for(int a = 0;a<=(mapSize-1);a++)
{
for(int b=0;b<=(mapSize-1);b++)
{
SimpleVector v1 = vertGrid[a][b];
SimpleVector v2 = vertGrid[a][b+1];
SimpleVector v3 = vertGrid[a+1][b+1];
SimpleVector v4 = vertGrid[a+1][b];
myObj.addTriangle(v1,-(texScale),-(texScale),
v2,-(texScale),texScale,
v3,(texScale),(texScale));
myObj.addTriangle(v4,texScale,-(texScale),
v1,-(texScale),-(texScale),
v3,texScale,texScale);

}
}




}

EgonOlsen

You mean a method that takes an array of vertices and creates the triangles from that like you do in your code "by hand"? No, there is no such thing ATM. I may add it, if it's really needed.
Alpha or transparency is only supported on a per Object3D base. That's mainly a tribut to the software rendering.
The order of the vertices that form a triangle counts, because it's used for backface culling. If your order is wrong, the triangle will de visible from the other side.
About the tiled terrain...i would say that it doesn't matter. jPCT will take care of the vertex sharing itself, you don't have to worry about it.

bgilb

no no, i dont need a method to do the job for me :D Im trying to create a grid of verts, then fill it with triangles myself. But for a unknown reason this line comes up ass Null:


           myObj.addTriangle(v1,-(texScale),-(texScale),
              v2,-(texScale),texScale,
              v3,(texScale),(texScale));

Edit: Im guessing jPCT combines all the verts at the same point? So something like SimpleVector[][] vertGrid = new SimpleVector[20][20];
would only create one vert at 0f,0f,0f..

bgilb

That problem is solved :D, but now for every vert, it has a extra triangle attatched to the vert at 0,0,0
|

everything works flawlessy now! check out my screenie :D little bit of photoshop added in to show you the tiles.
Now all i have to add it height of the verts, changing it so that every tile can change its texture

this is just the map editor btw.
http://lockandload.8m.com/terrainScreen1.jpg
copy paste it into your browser else it wont work :D