Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

Generating Outlines in OpenGL

, 7 Oct 2004
Using multi-pass techniques to generate outlines in OpenGL.
// CGLImage.cpp
//
// (c) W.Weyna 'Voytec'

#include "stdafx.h"
#include "OGLT.h"
#include "CGLImage.h"

//*******************************************************
//
// SwapRB()
//
//*******************************************************

void CGLImage::SwapRB()
{
	ASSERT(m_pDIBits);
	ASSERT(m_bih.biBitCount == 24 || m_bih.biBitCount == 32);

	GdiFlush();
	glFlush();

	const BYTE bPixelSizeBytes = m_bih.biBitCount / 8;

	BYTE bTemp = 0;
	for(BYTE* pbNextRow = m_pDIBits; 
	    pbNextRow < m_pDIBits + GetSize_Bytes(); 
		pbNextRow += GetAlignedRowSize_Bytes())
	{
		for(BYTE* pbPtr = pbNextRow; 
		    pbPtr < pbNextRow + GetRowSize_Bytes(); 
			pbPtr += bPixelSizeBytes)
		{
			bTemp = *pbPtr;
			*pbPtr = *(pbPtr+2);
			*(pbPtr+2) = bTemp;
		}
	}	
}	


//*******************************************************
//
// Render()
//
//*******************************************************

void CGLImage::Render(int x, int y, int z /* = 0 */)
{
	ASSERT(m_pDIBits);
	
	glRasterPos3i(x, y, z);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	glDrawPixels(m_bih.biWidth, m_bih.biHeight, GetImagePixelFormat(), GL_UNSIGNED_BYTE, m_pDIBits);
	glFlush();
	glFinish();
}


//*******************************************************
//
// GetImagePixelFormat()
//
//*******************************************************


int CGLImage::GetImagePixelFormat()
{
	switch(m_bih.biBitCount)
	{
	case 24: return GL_RGB;
	case 32: return GL_RGBA;
	}
	// Error, bad pixel format.
	ASSERT(0);
	return 0;
}


//*******************************************************
//
// GetImagePixelFormatName()
//
//*******************************************************


const char* CGLImage::GetImagePixelFormatName()
{
	switch(m_bih.biBitCount)
	{
	case 24: return "GL_RGB";
	case 32: return "GL_RGBA";
	}
	// Error, bad pixel format.
	ASSERT(0);
	return 0;
}


int CGLImage::GLPFtoBPP(const int nGLPForBPP)
{
	switch(nGLPForBPP)
	{
	case 1:
	case 4:
	case 8:
	case 16:
		// Not valid for OpenGL image
		ASSERT(0);
		return 24;
	case 24:
	case GL_RGB:
		return 24;
	case 32:
	case GL_RGBA:
		return 32;
	}
	// Invalid OpenGL image pixelformat name,
	// or invalid number of bits per pixel.
	ASSERT(0);
	return 24;
}


BOOL CGLImage::Lock()
{
	CString str;
	str.Format(_T("CGLImage%d"),(int)this);
	m_pThreadSynchro = new CMutex(FALSE,str);
	ASSERT(m_pThreadSynchro);
	m_pLock = new CSingleLock(m_pThreadSynchro);
	ASSERT(m_pLock);
	
	return m_pLock->Lock();
}

BOOL CGLImage::Unlock()
{
	BOOL result = m_pLock->Unlock();
	delete m_pThreadSynchro;
	delete m_pLock;

	return result;
}

BOOL CGLImage::IsLocked() const
{
	return m_pLock->IsLocked();
}

////////////////////////////////////////////////////////////////////////

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

Dave Handley
Web Developer
United Kingdom United Kingdom
I started programming on 8 bit machines as a teenager, writing my first compiled programming language before I was 16. I went on to study Engineering and Computer Science at Oxford University, getting a first and the University Prize for the best results in Computer Science. Since then I have worked in a variety of roles, involving systems management and development management on a wide variety of platforms. Now I manage a software development company producing CAD software for Windows using C++.
 
My 3 favourite reference books are: Design Patterns, Gamma et al; The C++ Standard Library, Josuttis; and Computer Graphics, Foley et al.
 
Outside computers, I am also the drummer in a band, The Unbelievers and we have just released our first album. I am a pretty good juggler and close up magician, and in my more insane past, I have cycled from Spain to Eastern Turkey, and cycled across the Namib desert.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 7 Oct 2004
Article Copyright 2004 by Dave Handley
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid