Advertisement

Playing AVI files....

Started by April 24, 2003 12:10 PM
4 comments, last by Angel_of_Death 21 years, 10 months ago
Hi! I know, there are already a few topics about this, but in none of them was a solution to my problem... I added NeHe''s AVI playing code to my own project(more or less just copy and paste), and then changed a few things, to support multiple textures... Well, the only thing that appears on the screen is a nice white block, where the video texture should actually be...(well, actually this white space seems to be the texture...) Has somebody had the same problem?(I''m pretty sure so...) And if yes, how were you able to solve it?(I hope you were...) thx
"Has somebody had the same problem?(I''m pretty sure so...)"
No, I haven''t had the problem.

"And if yes, how were you able to solve it?(I hope you were...)"
sorry.

"thx"
No problem





Visit
Advertisement
Great...

Well from former posts in this forum, I know there ARE ppl who got the same problem...

Maybe one of them managed to fix it...?
You may just be providing the load routine with the wrong path.

But perhaps this may help you out more. Heres the code from my AVI loader. See if you can find the problem yourself...that way you can benefit so that if you run into a similar problem you'll know what to do


      //code from AviStates.h://This is the definition for the states of an avi//this header is included just in case a state value is passed to a header//that does not include the scene base class header#ifndef SYS_AVI_STATE#define SYS_AVI_STATE//AVI State Values //starts the avi from the first frame#define AVI_START 0//stops the avi at the current frame#define AVI_STOP 1 //makes the avi loop#define AVI_LOOP 2//makes the avi play once#define AVI_NO_LOOP 3//makes the avi play foreward#define AVI_FOREWARD 4//makes the avi play in reverse#define AVI_REVERSE 5//makes the avi continue after a stop#define AVI_CONTINUE 6#endif///////////////////////////////////////////////////////////////////code from AviLoader.h://Defines a class that loads, plays and creates a texture from an avi file#ifndef SYS_AVI_LOADER#define SYS_AVI_LOADER//INCLUDES#include <windows.h>// Header File For The OpenGL32 Library#include <gl\gl.h>// Header File For The GLaux Library#include <gl\glaux.h>//Microsoft stuff to load the avi#include <vfw.h>#pragma comment(lib, "vfw32.lib")//the defines for the avi states - ex start, stop#include "AviStates.h"class AVI{public:	AVI()	{		CurFrame = 0;		hdc = CreateCompatibleDC(0);		// Grab A Device Context For Our Dib		hdd = DrawDibOpen();		data = 0;		ElapsedTime = 0;		glGenTextures(1, &Texture);		scale = 1;		Play = true;		looping = true;		Direction = true;	}	~AVI()	{		//close all our stuff		DeleteObject(hBitmap);		DrawDibClose(hdd);		AVIStreamGetFrameClose(pgf);		AVIStreamRelease(pavi);		AVIFileExit();	}	//Loads an avi file	bool Load(LPCSTR filename);	//Updates the avi image	void Update(DWORD milliseconds);	//Sets the frame to a specific location	void SetFrame(int Frame);	//Sets the avi's speed	void SetSpeed(float PlaySpeed)	{		scale = PlaySpeed;	}	void SetState(int State);	//Returns a texture to the current frame of the avi	GLuint GenTex();	//The AVI texture	GLuint Texture;	private:	int CurFrame;	//AVI stuff - taken directly from NeHe's avi lesson	AVISTREAMINFO psi;	PAVISTREAM pavi;	PGETFRAME pgf;	BITMAPINFOHEADER bmih;	int lastframe;	UINT width;	UINT height;	//the texture data	char * pdata;	//the frames per milliseconds	int MillisPerFrame;	int ElapsedTime;	//TEXTURE BITMAP stuff	HDRAWDIB hdd;	HBITMAP hBitmap;	HDC hdc;	//pointer to resized image	unsigned char * data;	//Play: to play or not to play	bool Play;	//Looping: true for looping	bool looping;	//Defines the direction for play:	//True for foreward, false for backward	bool Direction;	//the speed of the avi	float scale;};#endif///////////////////////////////////////////////////////////////////code from AviLoader.cpp://implementation for avi stuff#include "AviLoader.h"bool AVI::Load(LPCSTR filename){	//opens the avi file library	AVIFileInit();	//Opens the avi stream	if(AVIStreamOpenFromFile(&pavi,filename,streamtypeVIDEO,0,OF_READ,NULL) != 0)	{		//give an error		MessageBox(NULL,"Failed to Open the AVI Stream","AVI Error",MB_OK | MB_ICONEXCLAMATION);		//and give up		return false;	}	//read the avi info	AVIStreamInfo(pavi,ψ,sizeof(psi));	//calculate resolution	width = psi.rcFrame.right - psi.rcFrame.left;	height = psi.rcFrame.bottom - psi.rcFrame.top;	//grab the last frame	lastframe = AVIStreamLength(pavi);	//grab the length of time of a frame	MillisPerFrame = AVIStreamSampleToTime(pavi,1);	//Set up our bitmap stuff to resize our texture	bmih.biSize = sizeof(BITMAPINFOHEADER);	bmih.biPlanes = 1;	bmih.biBitCount = 24;	bmih.biWidth = 256;	bmih.biHeight = 256;	//requested compression mode	bmih.biCompression = BI_RGB;	//Create the dib	hBitmap = CreateDIBSection(hdc,(BITMAPINFO*)(&bmih),DIB_RGB_COLORS,(void**)(&data),NULL,NULL);	//select our hbitmap into our dc	SelectObject(hdc,hBitmap);	//create a getframe object	pgf = AVIStreamGetFrameOpen(pavi,NULL);	//check to see if we screwed up	if(pgf == NULL)	{		MessageBox(NULL,"Failed to create a GetFrame object","AVI Error",MB_OK | MB_ICONEXCLAMATION);		return false;	}	//now we have to create the gl texture	glGenTextures(1, &Texture);	glBindTexture(GL_TEXTURE_2D, Texture);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,data);		//and we didnt mess up so were done - at least thats the idea	return true;}void AVI::SetFrame(int Frame){	if((Frame <= lastframe) && (Frame >= 0))	{		ElapsedTime = Frame*MillisPerFrame;		CurFrame = Frame;	}}void AVI::Update(DWORD milliseconds){if(Play){	if(Direction)	{		ElapsedTime += (DWORD)(milliseconds*scale);		CurFrame = int((float)ElapsedTime/(float)MillisPerFrame);		if(CurFrame >= lastframe)		{			if(looping)			{				ElapsedTime = 0;				CurFrame = 0;			}			else			{				CurFrame = lastframe -1;			}		}			}	else	{		ElapsedTime -= (int)(milliseconds*scale);		CurFrame = int((float)ElapsedTime/(float)MillisPerFrame);					if(CurFrame < 0)		{			if(looping)			{				ElapsedTime = (lastframe-1)*MillisPerFrame;				CurFrame = lastframe-1;			}			else			{				CurFrame = 0;			}		}			}	}}GLuint AVI::GenTex(){	LPBITMAPINFOHEADER lpbi;	//grab the tex data	//clamp the current frame	if(CurFrame < 0)		CurFrame = 0;	if(CurFrame >= lastframe)		CurFrame = lastframe - 1;	lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, CurFrame);	pdata = (char*)lpbi + lpbi->biSize + lpbi->biClrUsed*sizeof(RGBQUAD);	DrawDibDraw(hdd,hdc,0,0,256,256,lpbi,pdata,0,0,width,height,0);	//flip the colors	void * b = data;	__asm	{		mov ecx,256*256		mov ebx, b		label:			mov al,[ebx+0]			mov ah,[ebx+2]			mov [ebx+2],al			mov [ebx+0],ah			add ebx,3			dec ecx			jnz label	}	glBindTexture(GL_TEXTURE_2D, Texture);	//update our texture	glTexSubImage2D(GL_TEXTURE_2D,0,0,0,256,256,GL_RGB,GL_UNSIGNED_BYTE,data);	return Texture;}void AVI::SetState(int State){	if(State == AVI_START)		SetFrame(0);	if(State == AVI_STOP)		Play = false;	if(State == AVI_CONTINUE)		Play = true;	if(State == AVI_LOOP)		looping = true;	if(State == AVI_NO_LOOP)		looping = false;	if(State == AVI_FOREWARD)		Direction = true;		if(State == AVI_REVERSE)		Direction = false;	}      


GenTex is the function you call in your draw routine. You only have to call it once though - after that you can just bind it's texture. If you have any questions just post....my commenting got messed up when i posted...sorry

[edited by - llvllatrix on April 24, 2003 8:22:01 PM]

[edited by - llvllatrix on April 24, 2003 8:24:04 PM]
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=35

~Main

==
Colt "MainRoach" McAnlis
Programmer
www.badheat.com/sinewave
==Colt "MainRoach" McAnlisGraphics Engineer - http://mainroach.blogspot.com
Thx llvllatrix, you''r code helped me to get it running
(I had made a few mistakes when creating the texture...)

This topic is closed to new replies.

Advertisement