A
download texture.cpp
Language: C++
LOC: 51
Project Info
TableHockey3D(tablehockey)
Server: SourceForge
Type: cvs
...ey\CVSROOT\tablehockey\src\
   Application.cpp
   Application.h
   Camera.cpp
   Camera.h
   Cube.cpp
   Cube.h
   Data.cpp
   Data.h
   Disk.cpp
   Disk.h
   FloatingText.cpp
   FloatingText.h
   Floor.cpp
   Floor.h
   Input.cpp
   Input.h
   Light.cpp
   Light.h
   log.cpp
   log.h
   main.cpp
   mmgr.cpp
   mmgr.h
   Model.cpp
   Model.h
   nommgr.h
   Puck.cpp
   Puck.h
   Pyramid.cpp
   Pyramid.h
   scene.cpp
   scene.h
   SmartPtr.h
   Sound.cpp
   Sound.h
   TableHockey.dsp
   TableHockey.dsw
   TestScene.cpp
   TestScene.h
   text.cpp
   text.h
   TextHelp.cpp
   TextHelp.h
   texture.cpp
   texture.h
   TexturedCube.cpp
   TexturedCube.h
   timer.cpp
   timer.h
   View.cpp
   View.h

/*=============================================================================
	texture.cpp: Basic OpenGL Framework texture function definitions

    Revision history:
	* Created by Zack Smith
	* Inspired by code written by NeHe (http://nehe.gamedev.net/)
=============================================================================*/

#include "application.h"
#include "log.h"
#include "texture.h"        // Header file that handles textures


/*-----------------------------------------------------------------------------
    CRender class function definitions.
-----------------------------------------------------------------------------*/

CTexture::CTexture()
{
	pApp->pLog->Log("Texture Class...intialized");
}

CTexture::~CTexture()
{
	glDeleteTextures(1, &texture2d);
	pApp->pLog->Log("Texture Class...destroyed");
}

AUX_RGBImageRec *CTexture::LoadBMP(char *Filename)
{
	FILE *File=NULL;									// File Handle

	if (!Filename)										// Make Sure A Filename Was Given
	{
		return NULL;									// If Not Return NULL
	}

	File=fopen(Filename,"r");							// Check To See If The File Exists

	if (File)											// Does The File Exist?
	{
		fclose(File);									// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}

	return NULL;										// If Load Failed Return NULL
}

int CTexture::LoadGLTexture(char *filename)
{
	int Status=FALSE;									// Status Indicator

	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture

	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL

	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if (TextureImage[0]=LoadBMP(filename))
	{
		Status=TRUE;									// Set The Status To TRUE

		glGenTextures(1, &texture2d);					// Create The Texture

		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture2d);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		
		// replace the previous line with these 2 if you want to use MipMapping
		//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
		//gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); 

	}

	if (TextureImage[0])									// If Texture Exists
	{
		if (TextureImage[0]->data)							// If Texture Image Exists
		{
			free(TextureImage[0]->data);					// Free The Texture Image Memory
		}

		free(TextureImage[0]);								// Free The Image Structure
	}
	return Status;										// Return The Status
}

/*-----------------------------------------------------------------------------
	The End.
-----------------------------------------------------------------------------*/

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us