OpenGL - 渲染纹理,颜色故障

时间:2014-04-05 20:29:27

标签: java opengl bytebuffer xuggle glteximage2d

我尝试使用 xuggle 渲染视频作为纹理,但我有一些麻烦...... 这是我的代码:

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

和视频阅读器 (另一个主题)

...

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

请告诉我,我做错了什么?我尝试更改 glTexImage2D 格式和类型,但只得到错误:(

结果图片(World render): enter image description here

修改 我的代码为灰色纹理:

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

0 个答案:

没有答案