Click here to Skip to main content
12,291,230 members (58,194 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads

Stats

87.2K views
3.7K downloads
32 bookmarked
Posted

Quagmire Particle Engine

, 23 Feb 2005
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

Share

About the Author

Ken Mazaika
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 23 Feb 2005
Article Copyright 2005 by Ken Mazaika
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid