Click here to Skip to main content
15,895,829 members
Articles / Multimedia / OpenGL

Pixel Shader for Edge Detection and Cartoon Effect

Rate me:
Please Sign up or sign in to vote.
4.88/5 (59 votes)
19 Aug 2010CPOL5 min read 158.1K   8.7K   106  
Implementation of Sobel Edge Detection and Cartoon Effect using pixel shader.
#include "StdAfx.h"
#include "GLVertexBuffer.h"


GLVertexBuffer::GLVertexBuffer(void)
{
	m_pVertexBuffer = 0;
	m_nCount = 0;
}

GLVertexBuffer::~GLVertexBuffer(void)
{
	Delete();
}

bool GLVertexBuffer::Create( int nCount_i )
{
	// Delete if already exists.
	Delete();

	m_nCount = nCount_i;
	m_pVertexBuffer = new GLVertex[nCount_i];
	if( 0 == m_pVertexBuffer )
	{
		return false;
	}
	memset( m_pVertexBuffer, 0, sizeof( GLVertex ) * m_nCount );
	return true;

}
void GLVertexBuffer::Delete()
{
	if( m_pVertexBuffer )
	{
		delete[] m_pVertexBuffer;
		m_pVertexBuffer = 0;
	}
}

// Here change vertex information of a particular index.
bool GLVertexBuffer::SetAt( int nIndex_i, float fX_i, float fY_i, float fZ_i, float fTu_i, float fTv_i )
{
	if( nIndex_i >= m_nCount  )
	{
		return false;
	}
	m_pVertexBuffer[nIndex_i].x = fX_i;
	m_pVertexBuffer[nIndex_i].y = fY_i;
	m_pVertexBuffer[nIndex_i].z = fZ_i;
	m_pVertexBuffer[nIndex_i].tu = fTu_i;
	m_pVertexBuffer[nIndex_i].tv = fTv_i;
	return true;
}

void GLVertexBuffer::DrawVertexBuffer( GLenum eDrawPrimitive_i )
{
	glBegin( eDrawPrimitive_i );
	for( int nIndex = 0; nIndex < m_nCount; ++nIndex )
	{
		GLVertex& Temp = m_pVertexBuffer[nIndex];
		glVertex3f( Temp.x, Temp.y, Temp.z );
		glTexCoord2f( Temp.tu, Temp.tv );
	}
	glEnd();
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


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

Comments and Discussions