Click here to Skip to main content
15,894,343 members
Articles / Database Development / SQL Server

Quagmire Particle Engine

Rate me:
Please Sign up or sign in to vote.
4.71/5 (19 votes)
23 Feb 20056 min read 106.2K   4.1K   32  
An object oriented OpenGL particle engine, for the simple creation of advanced particle effects.
/*	Ken Mazaika
	February 23, 2005
	Texture Engine
	Copyright 2005
	http://home.comcast.net/~kjmaz
  */

#include "qd.h"
#include <stdio.h>
#include "Texture.h"
#include <GL/glaux.h>
#include <GL/glu.h>
#include <fstream.h>


int QdTexture::SelectTexture()
{
	glBindTexture(GL_TEXTURE_2D, m_nTexture);
	return true;

}
int QdTexture::LoadFromBitmapResource(int nResource)
{
	HBITMAP hBMP;
	BITMAP	BMP;

	hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(nResource), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);


		if (hBMP)
		{
			GetObject(hBMP,sizeof(BMP), &BMP);
			glGenTextures(1, &m_nTexture);
			glBindTexture(GL_TEXTURE_2D, m_nTexture);
			gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

			//Automatically generate texture coordinates if desired
			if(m_bAutoTexture)
			{
				glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
				glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
				glEnable(GL_TEXTURE_GEN_S);
				glEnable(GL_TEXTURE_GEN_T);
			}

			DeleteObject(hBMP);
			return QD_SUCCESS;
		}
		else
		{
			
			return QD_INVALID_RESOURCE;
		}
	}


int QdTexture::LoadFromBitmap(char *szPath)
{
    FILE *fp;
    int nMemory;
	QD_BITMAP_IMAGE pbiTexture;

    fp = fopen(szPath, "rb");
    fread(&pbiTexture.bmfHeader, 1, 14, fp);
    fread(&pbiTexture.bmiHeader, 1, 40, fp);  

    if (pbiTexture.bmiHeader.biSizeImage == 0)
    {
        nMemory = pbiTexture.bmiHeader.biWidth * pbiTexture.bmiHeader.biHeight * 4;
    }
    else
    {
       nMemory = pbiTexture.bmiHeader.biSizeImage;
    }
   
    pbiTexture.image_data= new GLubyte[nMemory];

    fread(pbiTexture.image_data , 1, nMemory, fp);
    fclose(fp);

	glPixelStorei(GL_UNPACK_ALIGNMENT,1);
	glGenTextures(1, &m_nTexture);

	glBindTexture(GL_TEXTURE_2D, m_nTexture);
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pbiTexture.bmiHeader.biWidth, pbiTexture.bmiHeader.biHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, pbiTexture.image_data);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

	//Automatically generate texture coordinates if desired
	if(m_bAutoTexture)
	{
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
	
		glEnable(GL_TEXTURE_GEN_S);
		glEnable(GL_TEXTURE_GEN_T);
	}
	delete[] pbiTexture.image_data;
   return true;


}


QdTexture::QdTexture()
{
	m_bAutoTexture = 1;  //Set to autotexture by default
}

QdTexture::~QdTexture()
{

}

int QdTexture::SetMode(int nMode)
{
	if(nMode == QD_NO_AUTO_TEXTURE)
	{
		m_bAutoTexture = 0;
	}
	else if(nMode == QD_AUTO_TEXURE)
	{
		m_bAutoTexture = 1;
	}
	return QD_SUCCESS;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions