1

I'm trying render video as texture using xuggle, but i have some troubles... Here's my code:

ByteBuffer last = ent.oneBuffer;
if (ent.bufList.get(0) != null){
    last = ent.bufList.get(0);
}
last.rewind();
//last.flip();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200f, 100f);
GL11.glColor4f(1f, 1f, 1f, 1f);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, ent.texture.allocatedIndex);

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 1280, 720, 0, GL11.GL_RGB, GL12.GL_UNSIGNED_BYTE_3_3_2, last);
drawTexturedRect(x,y, width, height);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

if (ent.bufList.size() > 21){
    ent.bufList.remove(0);
}

And video reader (Another thread):

...

IMediaReader reader = ToolFactory.makeReader( new File("E:\\test.mp4").getAbsolutePath() );
reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
IMediaTool addTimeStamp = new TimeStampTool();
reader.addListener(addTimeStamp);
reader.open();

while(reader.readPacket() == null){
    reader.readPacket();
}

...

public List<ByteBuffer> bufList = new ArrayList();   
public class TimeStampTool extends MediaToolAdapter
{
    public long last = 0;
    @Override
    public void onVideoPicture(IVideoPictureEvent event)
    {
        bufList.add(event.getPicture().getByteBuffer());
    }
}            

Please tell me, what am I doing wrong? I tried changing glTexImage2D format and type, but got only errors :(

Result image (World render): enter image description here

EDIT: I have gray texture with that code:

GL11.glBindTexture(GL11.GL_TEXTURE_2D, ent.texture.allocatedIndex);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

int w = 1280 / 2;
GL11.glColor4ub((byte)255, (byte)255, (byte)255, (byte)255);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, w, (int)(w * 1.689f), 0, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, ent.oneBuffer);

enter image description here

Draiget
  • 113
  • 11
  • It would be good to see how result should look like. Or if not see, at least you could tell us. – Martin Perry Apr 05 '14 at 20:35
  • 1
    try `GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 1280, 720, 0, GL11.GL_BGR, GL12.GL_UNSIGNED_BYTE, last);`. according to `BufferedImage.TYPE_3BYTE_BGR` you have 3 bytes per pixel, not 1 byte splitted in 3/3/2 bits as `GL_UNSIGNED_BYTE_3_3_2` suggest – j-p Apr 05 '14 at 21:12
  • @j-p, i got error with that code: `**Caused by: java.lang.IllegalArgumentException:** Number of remaining buffer elements is 0, must be at least 2764800. Because at most 2764800 elements can be returned, a buffer with at least 2764800 elements is required, regardless of actual returned element count` – Draiget Apr 06 '14 at 07:10
  • @Martin Perry, at the end of the message there is a link `Result image (World render)` - [link](http://i.stack.imgur.com/UjgZx.png) EDIT: Added as image. – Draiget Apr 06 '14 at 07:11
  • @Draiget: what length has your buffer? check the width and height you pass to teximage2d, it should be your frame size – j-p Apr 06 '14 at 08:04
  • @j-p: ByteBuffer doesn't have length, ony: `java.nio.DirectByteBuffer[pos=0 lim=3110400 cap=3110400]` – Draiget Apr 06 '14 at 08:54
  • according to your code: w = 640;h = 1080 (strange values), so `GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 640, 1080, 0, GL11.GL_RGB, GL12.GL_UNSIGNED_BYTE_3_3_2, last);` – j-p Apr 06 '14 at 09:04
  • @j-p: problem not solved - http://i.gyazo.com/b23367221c3290e4f9d7da0f84aef8a7.png – Draiget Apr 06 '14 at 09:58

0 Answers0