• 大小: 3.48MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-12
  • 语言: 其他
  • 标签: OpenGL  贴图法    

资源简介

自己编写的OpenGL环境下的贴图方法来画树,只用了一点点基本的贴图方式,重点在于配置好的OpenGL环境.

资源截图

代码片段和文件信息

// basic.cpp : 定义应用程序的入口点。
//
#include “stdafx.h“

HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;

bool keys[256];
bool active=TRUE;
bool fullscreen=TRUE;

GLfloat xrot;
GLfloat yrot;
GLfloat zrot;

GLuint texture[1];

LRESULT CALLBACK WndProc(HWND UINT WPARAM LPARAM);

AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL;

if (!Filename)
{
return NULL;
}

File=fopen(Filename“r“);

if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}

return NULL;
}

int LoadGLTextures()
{
int Status=FALSE;

AUX_RGBImageRec *TextureImage[1];

memset(TextureImage0sizeof(void *)*1);           


if (TextureImage[0]=LoadBMP(“Data/example.bmp“))
{
Status=TRUE;

glGenTextures(1 &texture[0]);


glBindTexture(GL_TEXTURE_2D texture[0]);
glTexImage2D(GL_TEXTURE_2D 0 3 TextureImage[0]->sizeX TextureImage[0]->sizeY 0 GL_RGB GL_UNSIGNED_BYTE TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MIN_FILTERGL_LINEAR);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MAG_FILTERGL_LINEAR);
}

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}

free(TextureImage[0]);
}

return Status;
}

GLvoid ReSizeGLScene(GLsizei width GLsizei height)
{
if (height==0)
{
height=1;
}

glViewport(00widthheight);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();


gluPerspective(45.0f(GLfloat)width/(GLfloat)height0.1f100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int InitGL(GLvoid)
{
if (!LoadGLTextures())
{
return FALSE;
}

glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f 0.0f 0.0f 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST);
return TRUE;
}

int DrawGLScene(GLvoid) // 开始画图
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f0.0f-5.0f);

glRotatef(xrot1.0f0.0f0.0f);
glRotatef(yrot0.0f1.0f0.0f);
glRotatef(zrot0.0f0.0f1.0f);

glBindTexture(GL_TEXTURE_2D texture[0]);

glBegin(GL_POLYGON);

glTexCoord2f(0.0f 0.0f); glVertex3f(-1.0f -1.0f  0.0f);
glTexCoord2f(1.0f 0.0f); glVertex3f( 1.0f -1.0f  0.0f);
glTexCoord2f(1.0f 1.0f); glVertex3f( 1.0f  1.0f  0.0f);
glTexCoord2f(0.0f 1.0f); glVertex3f(-1.0f  1.0f  0.0f);

glEnd();

// xrot+=0.3f;
yrot+=0.2f;
// zrot+=0.4f;


return TRUE;
}

GLvoid KillGLWindow(GLvoid)
{
if (fullscreen)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10243  2009-06-14 03:44  basic\basic\basic.cpp

     文件         39  2009-05-12 13:58  basic\basic\basic.h

    .......     23558  2003-07-24 09:52  basic\basic\basic.ico

     文件       3347  2009-05-12 13:58  basic\basic\basic.rc

     文件       4611  2009-05-12 14:06  basic\basic\basic.vcproj

     文件       1409  2009-07-15 17:09  basic\basic\basic.vcproj.Roc-PC.Roc.user

     文件     196662  2004-09-01 10:26  basic\basic\data\example.BMP

     文件     196664  2009-06-13 16:21  basic\basic\data\example2.bmp

     文件        663  2009-05-12 14:03  basic\basic\Debug\basic.exe.embed.manifest

     文件        728  2009-05-12 14:03  basic\basic\Debug\basic.exe.embed.manifest.res

     文件        621  2009-06-14 03:44  basic\basic\Debug\basic.exe.intermediate.manifest

     文件      30753  2009-06-14 03:44  basic\basic\Debug\basic.obj

     文件    8257536  2009-06-06 17:18  basic\basic\Debug\basic.pch

     文件      48248  2009-05-12 14:02  basic\basic\Debug\basic.res

     文件       6134  2009-06-14 03:44  basic\basic\Debug\BuildLog.htm

     文件         63  2009-06-14 03:44  basic\basic\Debug\mt.dep

     文件     113009  2009-06-06 17:18  basic\basic\Debug\stdafx.obj

     文件     248832  2009-06-14 03:44  basic\basic\Debug\vc90.idb

     文件     389120  2009-06-14 03:44  basic\basic\Debug\vc90.pdb

     文件       1929  2009-05-12 13:58  basic\basic\ReadMe.txt

     文件        712  2009-05-12 13:58  basic\basic\Resource.h

    .......     23558  2003-07-24 09:52  basic\basic\small.ico

     文件        210  2009-05-12 13:58  basic\basic\stdafx.cpp

     文件        681  2009-06-06 17:18  basic\basic\stdafx.h

     文件       1026  2009-05-12 13:58  basic\basic\targetver.h

     文件    7908352  2009-07-15 17:09  basic\basic.ncb

     文件        881  2009-05-12 13:58  basic\basic.sln

    ..A..H.     12800  2009-07-15 17:09  basic\basic.suo

     文件     116224  2009-06-14 03:44  basic\Debug\basic.exe

     文件     598600  2009-06-14 03:44  basic\Debug\basic.ilk

............此处省略9个文件信息

评论

共有 条评论