Creating my own UV coordinates for texture and assign them to object

Started by Vziuh, August 01, 2011, 09:02:04 PM

Previous topic - Next topic

Vziuh

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.

EgonOlsen

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

Vziuh

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



                  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



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 ) ;

}






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.


Quote from: EgonOlsen on August 01, 2011, 09:14:00 PM
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.

EgonOlsen

This can't be what you wanted to do:


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

Vziuh

sure this was one of the problems, but that's not all, my screen is still blank =(
     



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.

EgonOlsen

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.

Vziuh

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

EgonOlsen