Jump to content

  • Log In with Google      Sign In   
  • Create Account

Radial Blur Code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 MENTAL   Members   -  Reputation: 382

Like
Likes
Like

Posted 15 October 2001 - 03:36 AM

alas, i am still ill, and therefor still playing about with any code i find. here''s the radial blur stuff:
  
// Radial.h


#ifndef __Radial
#define __Radial

#include <windows.h>
#include <gl\glut.h>

void radInit (int texWidth, int texHeight, int winWidth, int winHeight);
void radUninit ();

void radBegin ();
void radEnd ();

void radDraw (int texRepeat, float texIncrement);

void _radViewOrtho ();
void _radViewPerspective ();

#endif

  
  
// Radial.cpp


#include "Radial.h"

unsigned int _radTexID = 0;

int _radTexWidth  = 0;
int _radTexHeight = 0;
int _radWinWidth  = 0;
int _radWinHeight = 0;

void radInit (int texWidth, int texHeight, int winWidth, int winHeight)
{
	unsigned int* texData;

	int texSize = (texWidth * texHeight) * 4 * sizeof (unsigned int);

	texData = new GLuint[texSize];

	ZeroMemory (texData, texSize);

	glGenTextures (1, &_radTexID);

	glBindTexture (GL_TEXTURE_2D, _radTexID);

	glTexImage2D (GL_TEXTURE_2D, 0, 4, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);

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

	delete [] texData;

	_radTexWidth = texWidth;
	_radTexHeight = texHeight;

	_radWinWidth = winWidth;
	_radWinHeight = winHeight;
}

void radUninit ()
{
	glDeleteTextures (1, &_radTexID);
}

void radBegin ()
{
	glViewport (0, 0, _radTexWidth, _radTexHeight);
}

void radEnd ()
{
	glBindTexture (GL_TEXTURE_2D, _radTexID);

	glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, _radTexWidth, _radTexHeight, 0);

	glClearColor (0.0f, 0.0f, 0.0f, 0.5);
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glViewport (0, 0, _radWinWidth, _radWinHeight);
}

void radDraw (int texRepeat, float texIncrement)
{
	if (texRepeat <= 0)
		return;

	float spost = 0.0f;
	float alphainc = 0.9f / texRepeat;
	float alpha = 0.2f;

	glDisable (GL_TEXTURE_GEN_S);
	glDisable (GL_TEXTURE_GEN_T);

	glEnable (GL_TEXTURE_2D);
	glDisable (GL_DEPTH_TEST);
	glBlendFunc (GL_SRC_ALPHA,GL_ONE);
	glEnable (GL_BLEND);
	glBindTexture (GL_TEXTURE_2D, _radTexID);

	_radViewOrtho ();

	alphainc = alpha / texRepeat;

	glBegin (GL_QUADS);

		for (int i = 0; i < texRepeat; i++)
		{
			glColor4f (1.0f, 1.0f, 1.0f, alpha);

			glTexCoord2f (0 + spost, 1 - spost);	glVertex2f (0,            0);
			glTexCoord2f (0 + spost, 0 + spost);	glVertex2f (0,            _radWinHeight);
			glTexCoord2f (1 - spost, 0 + spost);	glVertex2f (_radWinWidth, _radWinHeight);
			glTexCoord2f (1 - spost, 1 - spost);	glVertex2f (_radWinWidth, 0);

			spost += texIncrement;
			alpha = alpha - alphainc;
		}

	glEnd ();

	_radViewPerspective ();

	glEnable (GL_DEPTH_TEST);

	glDisable (GL_TEXTURE_2D);
	glDisable (GL_BLEND);

	glBindTexture (GL_TEXTURE_2D, 0);
}

void _radViewOrtho ()
{
	glMatrixMode (GL_PROJECTION);

	glPushMatrix ();

	glLoadIdentity ();

	glOrtho (0, 640 ,480 , 0, -1, 1);

	glMatrixMode (GL_MODELVIEW);

	glPushMatrix ();

	glLoadIdentity ();
}

void _radViewPerspective ()
{
	glMatrixMode (GL_PROJECTION);
	glPopMatrix ();
	glMatrixMode (GL_MODELVIEW);
	glPopMatrix ();
}

  
instructions: radInit (blah, blah, blah, blah); radBegin (); //draw stuff radEnd (); //draw same stuff radBlur (bleh, 0.02f); makes life much easier . MENTAL

Sponsor:

#2 mittens   Moderators   -  Reputation: 1315

Like
Likes
Like

Posted 15 October 2001 - 01:59 PM

I was messing with that Saturday night... got it to work like a charm, NOT! hehe, looks like I may have to pirate some of that.

------------------------------
Trent (ShiningKnight)
E-mail me
ShiningKnight Games

#3 MENTAL   Members   -  Reputation: 382

Like
Likes
Like

Posted 16 October 2001 - 07:03 AM

you mean my elite version doesnt work or your quick trent-style hack (heh, like mine isnt) doesn''t work. mine works fine on my computer.

STOP NICKING MY DAMN CODE. first the cel-shading stuff, now this!!!

i think i''m gonna need 50% royalties the way you''re going

MENTAL


#4 mittens   Moderators   -  Reputation: 1315

Like
Likes
Like

Posted 16 October 2001 - 02:14 PM

Tee hee tee hee *giggle giggle*

I was kidding about stealing your code. Though my cel shading code is coming along nicely. Who knows when I''ll have my decked out demo and tutorial done though. :D

Actually, I''ve been getting into the demo-scene a lot lately, all these demo-effects are so much friggin'' fun, I can''t believe I didn''t find the joy in this earlier.

------------------------------
Trent (ShiningKnight)
E-mail me
ShiningKnight Games




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS