• Advertisement

Archived

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

i need the help from anyone

This topic is 5028 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

i am work to make a window i create it by GLUT lib i want it to prveiew a video i use NeHe lesson number 35 source the result a black window class_VSF.h source:


#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)

	}
}

BOOL Initialize ()					// Any GL Init Code & User Initialiazation Goes Here

{
	// Start Of User Initialization

	angle		= 0.0f;											// Set Starting Angle To Zero

	hdd = DrawDibOpen();										// Grab A Device Context For Our Dib

	glClearColor (0.0f, 0.0f, 0.0f, 0.5f);						// 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;												// 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);
	glLoadIdentity ();											// Reset The Modelview Matrix

	glTranslatef (0.0f, 0.0f, -10.0f);					// Grab A Frame From The AVI

												// Flush The GL Rendering Pipeline

	glFlush();
}
test.cpp source:
   
#include <iostream.h>
#include "r.h"
#include "class_VSF.h"



void init(void){

	Initialize();
}

void out(unsigned char key, int x, int y){
	switch (key){
	case 27:
		exit(0);
	}
}
void mode(){
	init();
	glutDisplayFunc(Draw) ;
	glutKeyboardFunc(out) ;
};
int main (int argc, char** argv){

	glutInit(&argc, argv) ;
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(500,500);
	glutInitWindowPosition(100,100);
	glutCreateWindow("test");
	mode();
	glutMainLoop() ;

	return 0 ;

}
[edited by - ff8 on May 18, 2004 3:58:10 AM] [edited by - ff8 on May 18, 2004 5:51:08 AM]

Share this post


Link to post
Share on other sites
Advertisement
as i think yes becaus when i open nehe lesson its work

Share this post


Link to post
Share on other sites
is there someone know something about this?

Share this post


Link to post
Share on other sites

  • Advertisement