📄 testtex2dvstexrect.cpp
字号:
// TestTex2DvsTexRect.cpp: implementation of the TestTex2DvsTexRect class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "shadow.h"
#include "TestTex2DvsTexRect.h"
#include "extgl.h"
#include "InitOpenGL.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define BigTexSize 512
#define MidTexSize 128
#define SmlTexSize 64
unsigned int CompTexID;
bool isLoaded = false;
void LoadTexDataTex2D(unsigned int &TexID)
{
int DimX,DimY;
unsigned char *ImageData = ReadTexImage("..\\pine.bmp", &DimX, &DimY );
glGenTextures(1,&TexID);
glBindTexture(GL_TEXTURE_2D,TexID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//// For max operation in a vector OK!
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, 3, DimX, DimY, 0, GL_RGB, GL_UNSIGNED_BYTE, ImageData );
delete []ImageData;
return;
}
void LoadTexRGBA(unsigned int &TexID)
{
int DimX,DimY;
unsigned char *ImageData = OpenTexImage4D("..\\AIRDROME2048.bmp", &DimX, &DimY );
glGenTextures(1,&TexID);
glBindTexture(GL_TEXTURE_2D,TexID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//// For max operation in a vector OK!
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, 4, DimX, DimY, 0, GL_RGBA, GL_UNSIGNED_BYTE, ImageData );
delete []ImageData;
return;
}
void LoadTexABGR_EXT(unsigned int &TexID)
{
int DimX,DimY;
unsigned char *ImageData = OpenTexImage4D("..\\AIRDROME2048.BMP", &DimX, &DimY );
glGenTextures(1,&TexID);
glBindTexture(GL_TEXTURE_2D,TexID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//// For max operation in a vector OK!
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, 4, DimX, DimY, 0, GL_ABGR_EXT, GL_UNSIGNED_BYTE, ImageData );
delete []ImageData;
return;
}
void LoadTexDataTexRECT(unsigned int &TexID)
{
int DimX,DimY;
unsigned char *ImageData = ReadTexImage("..\\pine.BMP", &DimX, &DimY );
glGenTextures(1,&TexID);
glBindTexture(GL_TEXTURE_RECTANGLE_NV,TexID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//// For max operation in a vector OK!
glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_RECTANGLE_NV, 0, 3, DimX, DimY, 0, GL_RGB, GL_UNSIGNED_BYTE, ImageData );
delete []ImageData;
return;
}
void TestTex2D()
{
int size = BigTexSize;
if(!isLoaded)
{
//LoadTexDataTex2D(CompTexID);
///The following compare RGBA <---> ABGR_EXT
LoadTexABGR_EXT(CompTexID);
//LoadTexRGBA(CompTexID);
isLoaded = true;
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,CompTexID);
glBegin( GL_QUADS );
glTexCoord2f(0, 0);
glVertex3d( 0, 0, 0 );
glTexCoord2f(1, 0);
glVertex3d( size, 0, 0 );
glTexCoord2f(1, 1);
glVertex3d( size, size, 0 );
glTexCoord2f(0, 1);
glVertex3d( 0, size, 0 );
glEnd();
}
void TestTexRect()
{
int size = BigTexSize;
if(!isLoaded)
{
LoadTexDataTexRECT(CompTexID);
isLoaded = true;
}
glEnable(GL_TEXTURE_RECTANGLE_NV);
glBindTexture(GL_TEXTURE_RECTANGLE_NV,CompTexID);
glBegin( GL_QUADS );
glTexCoord2f(0, 0);
glVertex3d( 0, 0, 0 );
glTexCoord2f(size, 0);
glVertex3d( size, 0, 0 );
glTexCoord2f(size, size);
glVertex3d( size, size, 0 );
glTexCoord2f(0, size);
glVertex3d( 0, size, 0 );
glEnd();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -