Glut and avi
my opengl app is based on Glut, but by following nehe's lesson 35, i could not get the avi rendered onto the surface of an object. Was it about the window created with Glut do not have compatibility to render the avi frames from the memory into the gl_buffer or what.
please advise.
GLUT has nothing to do with rendering an avi file. Just read one frame at a time and either use glDrawpixels or use texture mapping to display. I had done it recently and had no problem.
If you could not find the error, paste your code here.
If you could not find the error, paste your code here.
see this
main.cpp
main.h
there is one problem with freeing the data
please rate me :)
main.cpp
#include <iostream>#include "main.h"GLfloat fg,hh;void loop(void){ fg+=.3f; Update(); glutPostRedisplay();}void resize( int width, int height ) { if ( height == 0 ) { height = 1; } glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45.0f, ( GLfloat ) width / ( GLfloat ) height, 1, 150.0f ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); }void display(void){ glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GrabAVIFrame(frame); glLoadIdentity();glTranslatef(0,0,-15); glPushMatrix(); glBegin(GL_QUADS); glTexCoord2f(0.0f,1.0f); glVertex2f(-3.0f,3.0f); glTexCoord2f(1.0f,1.0f); glVertex2f(3.0f,3.0f); glTexCoord2f(1.0f,0.0f); glVertex2f(3.0f,-3.0f); glTexCoord2f(0.0f,0.0f); glVertex2f(-3.0f,-3.0f); glEnd(); glPopMatrix();glutSwapBuffers();}void init(void){Initialize ();}int main(int argc,char** argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(1000,700); glutInitWindowPosition(00,00); glutCreateWindow("testing window"); init(); glutDisplayFunc(display); glutReshapeFunc(resize); glutIdleFunc(loop); glutMainLoop(); Deinitialize(); return 0;}
main.h
#ifndef _WINDOWS_H_#include <windows.h>#endif#include <gl.h>#pragma comment( lib, "vfw32.lib" )#include <vfw.h> // User Defined Variablesint angle; int next; // Used For Animationfloat frame=0; // Frame Counterint effect; // Current Effectbool sp; // Space Bar Pressed?bool env=TRUE; // Environment Mapping (Default On)bool ep; // 'E' Pressed?bool bg=TRUE; // Background (Default On)bool bp; // 'B' Pressed?AVISTREAMINFO psi; // Pointer To A Structure Containing Stream InfoPAVISTREAM pavi; // Handle To An Open StreamPGETFRAME pgf; // Pointer To A GetFrame ObjectBITMAPINFOHEADER bmih; // Header Information For DrawDibDraw Decodinglong lastframe; // Last Frame Of The Streamint width; // Video Widthint height; // Video Heightchar *pdata; // Pointer To Texture Dataint mpf; // Will Hold Rough Milliseconds Per Frame // Storage For Our Quadratic ObjectsHDRAWDIB hdd; // Handle For Our DibHBITMAP hBitmap; // Handle To A Device Dependant BitmapHDC hdc = CreateCompatibleDC(0); // Creates A Compatible Device Contextunsigned char* data = 0; // Pointer To Our Resized Imagevoid flipIt(void* buffer) // Flips The Red And Blue Bytes (256x256){ void* b = buffer; // Pointer To The Buffer __asm // Assembler Code To Follow { mov ecx, 256*256 // Counter Set To Dimensions Of Our Memory Block mov ebx, b // Points ebx To Our Data (b) label: // Label Used For Looping mov al,[ebx+0] // Loads Value At ebx Into al mov ah,[ebx+2] // Loads Value At ebx+2 Into ah mov [ebx+2],al // Stores Value In al At ebx+2 mov [ebx+0],ah // Stores Value In ah At ebx add ebx,3 // Moves Through The Data By 3 Bytes dec ecx // Decreases Our Loop Counter jnz label // If Not Zero Jump Back To Label }}void OpenAVI(LPCSTR szFile){ // Opens An AVI File (szFile) AVIFileInit(); AVIStreamOpenFromFile(&pavi, szFile, streamtypeVIDEO, 0, OF_READ, NULL); AVIStreamInfo(pavi, &psi, sizeof(psi)); // Reads Information About The Stream Into psi width=psi.rcFrame.right-psi.rcFrame.left; // Width Is Right Side Of Frame Minus Left height=psi.rcFrame.bottom-psi.rcFrame.top; // Height Is Bottom Of Frame Minus Top lastframe=AVIStreamLength(pavi); // The Last Frame Of The Stream mpf=AVIStreamSampleToTime(pavi,lastframe)/lastframe; // Calculate Rough Milliseconds Per Frame bmih.biSize = sizeof (BITMAPINFOHEADER); // Size Of The BitmapInfoHeader bmih.biPlanes = 1; // Bitplanes bmih.biBitCount = 24; // Bits Format We Want (24 Bit, 3 Bytes) bmih.biWidth = 256; // Width We Want (256 Pixels) bmih.biHeight = 256; // Height We Want (256 Pixels) bmih.biCompression = BI_RGB; // Requested Mode = RGB hBitmap = CreateDIBSection (hdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&data), NULL, NULL); SelectObject (hdc, hBitmap); // Select hBitmap Into Our Device Context (hdc) pgf=AVIStreamGetFrameOpen(pavi, NULL); // Create The PGETFRAME Using Our Request Mode}void GrabAVIFrame(int frame) // Grabs A Frame From The Stream{ LPBITMAPINFOHEADER lpbi; // Holds The Bitmap Header Information lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame); // Grab Data From The AVI Stream pdata=(char *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD); // Pointer To Data Returned By AVIStreamGetFrame // Convert Data To Requested Bitmap Format DrawDibDraw (hdd, hdc, 0, 0, 256, 256, lpbi, pdata, 0, 0, width, height, 0); flipIt(data); // Swap The Red And Blue Bytes (GL Compatability) glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 250, GL_RGB, GL_UNSIGNED_BYTE, data);}void CloseAVI(void) // Properly Closes The Avi File{ DeleteObject(hBitmap); // Delete The Device Dependant Bitmap Object DrawDibClose(hdd); // Closes The DrawDib Device Context AVIStreamGetFrameClose(pgf); // Deallocates The GetFrame Resources AVIStreamRelease(pavi); // Release The Stream AVIFileExit(); // Release The File}void Update () // Perform Motion Updates Here{// next+=milliseconds; // Increase next Based On The Timer// frame=next/mpf; frame++ ; // Calculate The Current Frame if (frame>=lastframe) // Are We At Or Past The Last Frame? { frame=0; // Reset The Frame Back To Zero (Start Of Video) //next=0; // Reset The Animation Timer (next) }}void Initialize () // Any GL Init Code & User Initialiazation Goes Here{ // Start Of User Initialization angle = 0.0f; // Set Starting Angle To Zero hdd = DrawDibOpen(); glEnable(GL_TEXTURE_2D);// Grab A Device Context For Our Dib glClearColor (0.0f, 0.0f, 0.0f,0); // Black Background glClearDepth (1.0f); // Depth Buffer Setup glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal) glEnable(GL_DEPTH_TEST); // Enable Depth Testing glShadeModel (GL_SMOOTH); // Select Smooth Shading glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate // Create Texture Coords glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // Set Texture Max Filter glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // Set Texture Min Filter glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set The Texture Generation Mode For S To Sphere Mapping glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set The Texture Generation Mode For T To Sphere Mapping OpenAVI("data/face.avi"); // Open The AVI File // Create The Texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data); // Return TRUE (Initialization Successful)}void Deinitialize (void) // Any User DeInitialization Goes Here{ delete data; delete pdata; CloseAVI(); // Close The AVI File}
there is one problem with freeing the data
please rate me :)
i was following those code and also from nehe lesson 35 and had track every step carefully. But the diff was that my code did used other bitmap testures besides the avi file.
The bitmap testures comes on ok but not the avi frames.
ciao
The bitmap testures comes on ok but not the avi frames.
ciao
Did you check if the AVI file is read correctly ?
Try to read and then write the avi file without displaying it. That way you know if the program is reading the avi correctly. Or else paste some code here.
In file Main.h:-
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 250, GL_RGB, GL_UNSIGNED_BYTE, data);
Is the sixth argument 250 ?
Also what is the dimension of an individual frame ? Is it POT in both dimensions otherwise for NPOT use GL_TEXTURE_RECTANGLE_ARB.
Try to read and then write the avi file without displaying it. That way you know if the program is reading the avi correctly. Or else paste some code here.
In file Main.h:-
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 250, GL_RGB, GL_UNSIGNED_BYTE, data);
Is the sixth argument 250 ?
Also what is the dimension of an individual frame ? Is it POT in both dimensions otherwise for NPOT use GL_TEXTURE_RECTANGLE_ARB.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement