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

📄 opengl.cpp

📁 是3D游戏一书中所讲的游戏引擎fly3D 包括fly3D引擎的源码及应用此引擎开发出来的游戏实例 有fly3D引擎的教程,易于step by step跟学
💻 CPP
字号:
#include "../../lib/Fly3D.h"
#include "opengl.h"

HGLRC m_hRC;

unsigned char halftone[]=
{
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
	0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
};

int CreateView(HDC hdc)
{
	PIXELFORMATDESCRIPTOR pfd, *ppfd;
	int pixelformat;

	ppfd = &pfd;
	memset(ppfd,0,sizeof(PIXELFORMATDESCRIPTOR));

	ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
	ppfd->nVersion = 1;
	ppfd->dwFlags =	PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
	ppfd->iPixelType = PFD_TYPE_RGBA;
	ppfd->cColorBits = 0;
	ppfd->cDepthBits = 0;
	ppfd->cAccumBits = 0;
	ppfd->cStencilBits = 0;

	pixelformat = ChoosePixelFormat(hdc, ppfd);

	if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE) 
		return FALSE;

	m_hRC = wglCreateContext( hdc );

	wglMakeCurrent( hdc, m_hRC );

	return 1;
}

void DeleteView()
{
	if (m_hRC==0)
		return;

	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(m_hRC);
	m_hRC=0;
}

void ResizeView(int sx,int sy)
{
	if (m_hRC==0)
		return;
    glViewport(0, 0, sx, sy);
}

void InitView()
{
	glShadeModel(GL_FLAT);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
	glDisable(GL_DITHER);
	glDisable(GL_FOG);
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);

	glDisable(GL_LINE_SMOOTH);
	glDisable(GL_POLYGON_SMOOTH);

	float f[4]={ 0,0,0,1 };
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,f);

	glClearColor( 1,1,1,1 );
    glClearDepth( 1 );

	glDrawBuffer(GL_BACK_LEFT);
	glReadBuffer(GL_BACK_LEFT);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 90, 1, NEAR_PLANE, FAR_PLANE);
    glMatrixMode( GL_MODELVIEW );

	glPolygonStipple(halftone);
}

⌨️ 快捷键说明

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