Author Topic: Creating my own UV coordinates for texture and assign them to object  (Read 4629 times)

Offline Vziuh

  • byte
  • *
  • Posts: 13
    • View Profile
Hello everyone, I’m working on interface classes, main idea is, to create a plan ( at the moment I don’t  know how to set adequate dimensions to this plane, so my 2d image what i use like texture for interface will look without changes )

But, thing is that I need to set this image like texture on the plane, I need to create some UV coordinates, but I didn’t find how to assign them to the object.

Help me plz, if you have some better ideas about how to create interface =) share please.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #1 on: August 01, 2011, 09:14:00 pm »
You can either assign them on creation with the appropriate addTriangle() method or for an existing object by using the PolygonManager.

Apart from that, i usually blit my interface components to the screen using the methods in FrameBuffer. But then again, my interfaces are pretty simple...

Offline Vziuh

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #2 on: August 02, 2011, 10:28:02 am »
The method with adding triangles would be great if it will work =)

As result I have blank screen

Here’s code where I create plane


Code: [Select]
                  public Picture_plane ( Context context , String address )
    {

object = new Object3D ( 1 ) ;

SimpleVector sv1 = new SimpleVector () ;
SimpleVector sv2 = new SimpleVector () ;
SimpleVector sv3 = new SimpleVector () ;

float u1 ;
float v1 ;

float u2 ;
float v2 ;

float u3 ;
float v3 ;

sv1.set( 0 , 0 , 0 ) ;
sv1.set(  2 , 0 , 0 ) ;
sv1.set( 0 ,  2 , 0 ) ;

u1 = 0.0f ;
v1 = 0.0f ;

u2 = 0.0f ;
v2 = 1.0f ;

u3 = 1.0f ;
v3 = 0.0f ;

object.addTriangle( sv1 , u1 , v1 , sv2 , u2 , v2 , sv3 , u3 , v3 ) ;


Texture texture = new Texture ( loade_texture ( context , address ) ) ;
TextureManager.getInstance().addTexture ( "diffuse" , texture ) ;

object.setTexture( "diffuse" ) ;

object.strip() ;
object.build() ;

    }


Here’s code where I’m adding this plane to the world object and onDrawFrame function

Code: [Select]

public void onSurfaceChanged(GL10 gl , int w , int h )
{

world = new World () ;

world.addObject(  Storage_2d.picture_plane[ 0 ].object ) ;

Camera cam = world.getCamera();

SimpleVector sv = Storage_2d.picture_plane [ 0 ].object.getTransformedCenter() ;

cam.lookAt ( sv ) ;

cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);

frame_buffer = new FrameBuffer ( gl , w , h ) ;

}



Code: [Select]

public void onDrawFrame( GL10 gl )
{

frame_buffer.clear( back_color ) ;

world.renderScene ( frame_buffer )  ;
world.draw             ( frame_buffer )  ;

frame_buffer.display();

}


I've tried to create another objects from Primitives class, and if I create cube everything is ok, i can see it on the screen, but this plane.


Apart from that, i usually blit my interface components to the screen using the methods in FrameBuffer. But then again, my interfaces are pretty simple...

Can you share example of code how to blit.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #3 on: August 02, 2011, 10:52:19 am »
This can't be what you wanted to do:

Code: [Select]
sv1.set( 0 , 0 , 0 ) ;
sv1.set(  2 , 0 , 0 ) ;
sv1.set( 0 ,  2 , 0 ) ;

Offline Vziuh

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #4 on: August 02, 2011, 04:12:42 pm »
sure this was one of the problems, but that’s not all, my screen is still blank =(
     

Code: [Select]

sv1.set( 0 , 0 , 0 ) ;
sv2.set( 1 , 0 , 0 ) ;
sv3.set( 0 , 1 , 0 ) ;



also i have proposal, people can complete documentation about this game engine, they could attach their source code in description, so after reading theory part you'll be able to see how to use it.

I didn’t understand how to use BLITing and google didn’t help me.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #5 on: August 02, 2011, 04:18:43 pm »
Keep in mind that order matters. Try a plane.setCulling(false); to see if that makes your plane appear. If it does, switch vertex order.

Blitting is easy. Just create an image with the content you want to blit on screen, load it as a texture (doesn't have to added to the TextureManager, but it doesn't hurt either) and use it within the blit methods to blit the whole image or parts of it to the screen. You should be able to find some source code that does this in the Alien Runner sources.
« Last Edit: August 02, 2011, 04:41:45 pm by EgonOlsen »

Offline Vziuh

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #6 on: August 03, 2011, 09:29:26 am »
Bliting works almost very fine, thanks a lot !

But I see that semitransparent pixels didn’t output

here is initial png picture:




and here's what i have on the screen:






I thought  that I need to use .setEffect() method, but didn’t find how to work with ITextureEffect interface

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #7 on: August 03, 2011, 09:42:48 am »
Create the texture with one of these constructors: http://www.jpct.net/doc/com/threed/jpct/Texture.html#Texture(java.lang.String, boolean). Otherwise, jPCT will calculate it's own alpha channel.

Offline Vziuh

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Creating my own UV coordinates for texture and assign them to object
« Reply #8 on: August 03, 2011, 09:45:26 am »
YEY it works ! thx a lot !