⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wince_opengl.cpp

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 CPP
字号:
/* PocketCultMAME - MAME Emulator for PocketPC
   (c) Copyright 2006 Manuel Castrillo Mart韓ez

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifdef OPENGL_BUILD

#include <windows.h>

#include "GLES/egl.h"
#include "vidogl.h"

#pragma comment(lib,"\\OpenGLES\\Builds\\OGLES\\PocketPCARMV4\\Lib\\libGLES_CL.lib")

EGLDisplay			v_eglDisplay;
EGLConfig			v_eglConfig;
EGLContext			v_eglContext;
EGLSurface			v_eglWindowSurface;

const unsigned int PRECISION = 16;
const GLfixed ONE  = 1 << PRECISION;
const GLfixed ZERO = 0;

inline GLfixed FixedFromInt(int value) {return value << PRECISION;};
inline GLfixed FixedFromFloat(float value) {return static_cast<GLfixed>(value * static_cast<float>(ONE));};
inline GLfixed MultiplyFixed(GLfixed op1, GLfixed op2) {return (op1 * op2) >> PRECISION;};

extern "C"
{
	GLuint textureID[20];
	unsigned short * textureBitmap[20];
	int xTextureCount, yTextureCount;
}

GLshort vertices[ 20*20*12 ];
static GLfixed texCoords[] = { 0,0,  ONE,0,  0,ONE,  ONE,ONE };


bool OpenGLinit( HWND hWnd )
{

	EGLint s_configAttribs[] =
	{
		EGL_ALPHA_SIZE,		0,
		EGL_RED_SIZE,		5,
		EGL_GREEN_SIZE,		6,
		EGL_BLUE_SIZE,		5,
		EGL_SURFACE_TYPE,	EGL_DONT_CARE,
		EGL_NONE 
	};
	EGLint numConfigs;
	EGLint majorVersion;
	EGLint minorVersion;
	EGLBoolean success;

	// Init OPENGL
	v_eglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
	eglGetConfigs( v_eglDisplay, NULL, 0, &numConfigs );
	eglInitialize( v_eglDisplay, &majorVersion, &minorVersion );
	eglChooseConfig( v_eglDisplay, s_configAttribs, &v_eglConfig, 1, &numConfigs );
	v_eglContext = eglCreateContext( v_eglDisplay, v_eglConfig, NULL, NULL );

	v_eglWindowSurface = eglCreateWindowSurface( v_eglDisplay, v_eglConfig, hWnd, NULL );
	success = eglMakeCurrent( v_eglDisplay, v_eglWindowSurface, v_eglWindowSurface, v_eglContext );

	if( success )
	{
		glClearColorx(0, 0, 0, 0);

		glDisable(GL_BLEND);
		glDisable(GL_ALPHA_TEST);
		glDisable(GL_LIGHTING);

		glViewport(0, 0, 480, 640);
	}

	return( success );

}


void OpenGLclose(void)
{
//	eglSwapBuffers (v_eglDisplay, v_eglWindowSurface);
//	eglMakeCurrent(v_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) ;
	eglDestroyContext(v_eglDisplay, v_eglContext);
	eglDestroySurface(v_eglDisplay, v_eglWindowSurface);
	eglTerminate(v_eglDisplay);
}


void adjustOpenGLview( int x, int y )
{

	int totalTextures;
	
	// Sets orthographic view

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();    
	
	glOrthox( FixedFromInt(0), FixedFromInt(x),
			  FixedFromInt(0), FixedFromInt(y), 
			  FixedFromInt(-1),FixedFromInt(1) );

	glMatrixMode(GL_MODELVIEW);

	// Screen is divided in 64x64 textures, this creates the needed textures.
	
	xTextureCount = (int)ceil( ((double)x) / 64 );
	yTextureCount = (int)ceil( ((double)y) / 64 );

	totalTextures = xTextureCount * yTextureCount;

	for( int lp=0; lp < totalTextures; lp++ )
	{
		createTexture( lp );
	}

	// Creates polys
	int county = 64*yTextureCount;

	for( int ly=0; ly < yTextureCount; ly++ )
	{
		for( int lx=0; lx < xTextureCount; lx++ )
		{
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+0 ] = 64*lx;
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+1 ] = county;
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+2 ] = 0;

			vertices[ (ly*(xTextureCount*12)) + (lx*12)+3 ] = 64*(lx+1);
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+4 ] = county;
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+5 ] = 0;

			vertices[ (ly*(xTextureCount*12)) + (lx*12)+6 ] = 64*lx;
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+7 ] = county-64;
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+8 ] = 0;

			vertices[ (ly*(xTextureCount*12)) + (lx*12)+9 ] = 64*(lx+1);
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+10] = county-64;
			vertices[ (ly*(xTextureCount*12)) + (lx*12)+11] = 0;
		}
		county-=64;
	}

}

void createTexture( int textureNumber )
{

	textureBitmap[textureNumber] = (unsigned short *)malloc( 64*64*2 );

	glGenTextures( 1, &textureID[textureNumber] );
	glBindTexture( GL_TEXTURE_2D, textureID[textureNumber] );
	glTexParameterx( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	glTexParameterx( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned short *)textureBitmap[textureNumber] );

}

void OpenGLrender(void)
{

long ticksForThisFrame = GetTickCount();
long aa;

	*(DWORD *)(0xBC000000 + 0x03fe2188) &= 0x3FFFFFFF;
	*(DWORD *)(0xBC000000 + 0x03fe0064) |= 0x4;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  

	glLoadIdentity();

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glActiveTexture(GL_TEXTURE0);
	glClientActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);

	for( int ly=0; ly < yTextureCount; ly++ )
	{
		for( int lx=0; lx < xTextureCount; lx++ )
		{
			glBindTexture(GL_TEXTURE_2D, textureID[ lx+(ly*xTextureCount) ]);
			glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 64, 64, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureBitmap[ lx+(ly*xTextureCount) ] );
			glTexCoordPointer(2, GL_FIXED, 0, texCoords);
			glVertexPointer(3, GL_SHORT, 0, &vertices[ (ly*(xTextureCount*12))+(lx*12) ]);
			glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		}
	}

	aa = GetTickCount() - ticksForThisFrame;

	eglSwapBuffers(v_eglDisplay, v_eglWindowSurface);

}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -