Archived

This topic is now archived and is closed to further replies.

I need help

This topic is 4952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello evreyone i want ask if i can to load avi and display evrey frame i want the simple way for it by the way i''m using glut for my window NOT windows.h thanks all bye!

Share this post


Link to post
Share on other sites
but i'm using window i creat it with opengl not windows.h
NehE lessons use window from windows library

[edited by - ff8 on May 19, 2004 1:06:01 PM]

Share this post


Link to post
Share on other sites
i was tring to change the window system from windows.h to glut.h from NeHe lesson
but it doesn''t work

class_VSF.h:



#ifndef _WINDOWS_H_
#include <windows.h>
#endif

#pragma comment( lib, "vfw32.lib" )
#include <vfw.h>




// User Defined Variables

int angle;
int next; // Used For Animation

int frame=0; // Frame Counter

int effect; // Current Effect

bool 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 Info

PAVISTREAM pavi; // Handle To An Open Stream

PGETFRAME pgf; // Pointer To A GetFrame Object

BITMAPINFOHEADER bmih; // Header Information For DrawDibDraw Decoding

long lastframe; // Last Frame Of The Stream

int width; // Video Width

int height; // Video Height


char *pdata; // Pointer To Texture Data

int mpf; // Will Hold Rough Milliseconds Per Frame


GLUquadricObj *quadratic; // Storage For Our Quadratic Objects


HDRAWDIB hdd; // Handle For Our Dib

HBITMAP hBitmap; // Handle To A Device Dependant Bitmap

HDC hdc = CreateCompatibleDC(0); // Creates A Compatible Device Context

unsigned char* data = 0; // Pointer To Our Resized Image


void 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

if (pgf==NULL)
{
// An Error Occurred Opening The Frame

MessageBox (HWND_DESKTOP, "Failed To Open The AVI Frame", "Error", MB_OK | MB_ICONEXCLAMATION);
}
}

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 (DWORD milliseconds) // Perform Motion Updates Here

{

next+=milliseconds; // Increase next Based On The Timer

frame=next/mpf; // 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


quadratic=gluNewQuadric(); // Create A Pointer To The Quadric Object

gluQuadricNormals(quadratic, GLU_SMOOTH); // Create Smooth Normals

gluQuadricTexture(quadratic, GL_TRUE); // 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/face2.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

{
CloseAVI(); // Close The AVI File

}



void Draw (void) // Draw Our Scene

{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer


GrabAVIFrame(frame); // Grab A Frame From The AVI



glLoadIdentity();
glColor3i(1,1,1);// Reset The Modelview Matrix

glBegin(GL_QUADS); // Begin Drawing The Background (One Quad)

// Front Face

glTexCoord2f(1.0f, 1.0f); glVertex3f( 11.0f, 8.3f, -20.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-11.0f, 8.3f, -20.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-11.0f, -8.3f, -20.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 11.0f, -8.3f, -20.0f);
glEnd(); // Done Drawing The Background


glLoadIdentity (); // Reset The Modelview Matrix

glTranslatef (0.0f, 0.0f, -0.0f); // Translate 10 Units Into The Screen


glFlush (); // Flush The GL Rendering Pipeline

}



r.h:

#pragma message ("SqlLib By:squall e-mail:yyytt24@hotmail.com")
#include <stdarg.h>
#include <glut.h>
#include <glu.h>
#include <gl.h>
#include <string.h>
#include <math.h>
#include <conio.h>



test.cpp:

#include <iostream>
#include "r.h"
#include "class_VSF.h"

void init(void){

Initialize();
}

void mode(){


glutDisplayFunc(Draw) ;

};
int main (int argc, char** argv){

glutInit(&argc, argv) ;
init();
glutInitDisplayMode(20);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("videw preview");
mode();

glutMainLoop() ;

return 0 ;


}


there''s no errors but the reslut from this codes a black blank window
what is the problem ??


Share this post


Link to post
Share on other sites