Как отрендерить видео с DirectShow в OpenGL текстуру?
Пробовал так:
var
Bits: PByte;
...
procedure TfrmRenderer.DoRenderSample(Sample : IMediaSample);
begin
Sample.GetPointer(bits);
end;
procedure TfrmRenderer.SetupGL;
begin
glClearColor(0.3,0.4,0.7,0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.9);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
end;
procedure TfrmRenderer.Render;
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glViewport(0,0,ClientWidth,ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(45.0,ClientWidth/ClientHeight,NearClipping,FarClipping);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glTranslatef(0,0,-3);
glBindTexture(GL_TEXTURE_2D,gltexture);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(-1, 1, -1);
glTexCoord2f(1, 0); glVertex3f(1, 1, -1);
glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
GLEnd;
SwapBuffers(dc);
end;
procedure TfrmRenderer.IdleHandler(Sender : TObject; var Done : Boolean);
begin
Render;
Sleep(1);
Done := False;
LoadTextureFromByte(bits,gltexture,fWidth,fHeight);
end;
function CreateTexture(Width, Height, Format:Word;pData:Pointer):Integer;
var
Texture : GLuint;
begin
glGenTextures(1, Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if Format = GL_RGBA then
gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,Width,Height,GL_RGBA,GL_UNSIGNED_BYTE, pData)
else
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData);
result :=Texture;
end;
function LoadByteTexture(pData: pointer; var Texture : GLuint; width,height:integer) : Boolean;
begin
Texture :=CreateTexture(Width, Height, GL_RGB, pData);
result :=TRUE;
end;
function LoadTextureFromByte(fData: Pointer; var Texture : GLuint; width,height:integer) : Boolean;
begin
LoadByteTexture(fData,Texture,width,height)
end;
Вылетает с "Access violation at address 6B6C70E5 in module 'GLUT32.dll'. Read of address 00000000" на процедуре:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData);
Что делать?