Advertisement

big problem with my program about radial blur :-(

Started by June 23, 2003 01:28 PM
1 comment, last by airseb 21 years, 8 months ago
Hi, i have read the lesson 36 of nehe and i have decided of making my own program about radial blur. But i have a problem : the big texture that we create and render and witch has like size 640x480 don''t want to be displayed. i don''t understand why ! can you help me ? this is the code (where i show in commentary what part of the program don''t want to be displayed (at the end)) : this is first, the main function :

#include "main.h"

unsigned int textureNumber ;
Texture *CreateTexture ;



void reshape (int w, int h)
{
	glViewport (0, 0, w, h) ;

	glMatrixMode (GL_PROJECTION) ;
	glLoadIdentity () ;

	glFrustum(-5.0 , 5.0, -5.0, 5.0, 5.0, 500.0); //perspective conique
	glPushMatrix () ; //permet de revenir à la perspective conique de glFrustum avec glPopMatrix
	
	glMatrixMode(GL_MODELVIEW); //la matrice active de modelisation/visualisation sera affectée
	glLoadIdentity(); //charge la matrice identité

	gluLookAt (0, 5, 70, 0, 0, 0, 0, 1, 0) ;
	//les 3 premières données sont les coordonnées de la caméra, 
	//les 3 suivantes désignent la cible, et les 3 suivantes, le haut de la caméra suivant un axe(ici y)

}


void display ()
{	
	glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;
	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL) ;
	
	
	CreateTexture->RadialBlur() ; //rend dans la texture et la blur
	
	
	/*AUX_RGBImageRec *texture1; 
	texture1 = auxDIBImageLoad("tex.bmp");
	unsigned int texname ;
	glGenTextures (1, &texname) ;
	glBindTexture (GL_TEXTURE_2D, texname) ;
	
	
	glTexParameteri (GL_TEXTURE_2D,	GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri (GL_TEXTURE_2D,	GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	
	glTexImage2D(GL_TEXTURE_2D, 0, 3, (texture1)->sizeX, (texture1)->sizeY,
					0, GL_RGB, GL_UNSIGNED_BYTE, (texture1)->data);
	 
	glBindTexture(GL_TEXTURE_2D, texname);
	glBegin(GL_QUADS);
	glColor3f(1.0,1.0,1.0);
		glTexCoord2f(0,0);glVertex2f(-1,-1);
		glTexCoord2f(1,0);glVertex2f(1,-1);
		glTexCoord2f(1,1);glVertex2f(1,1);
		glTexCoord2f(0,1);glVertex2f(-1,1);
	glEnd();*/
	
	glutWireCube (20) ;
	
	glutSwapBuffers() ;

}
	

void main (int argc, char** argv)
{
		
		
	//cout<<"hello"< 

then this is the code about radial blur :


#include "main.h"


void Texture::BlendingOrthoOn ()
{
	glDisable(GL_DEPTH_TEST);					
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	glEnable(GL_BLEND);
	
	glMatrixMode (GL_PROJECTION) ;
	//glLoadIdentity();
	glOrtho ( 0, screenWidth , screenHeight , 0, -1, 1) ; //spécifie un repère dont l''origine
														//est en haut a gauche
	
	glMatrixMode(GL_MODELVIEW); 
	//glLoadIdentity();
	
}


void Texture::BlendingOrthoOff ()
{	
	glMatrixMode (GL_PROJECTION) ;
	glPopMatrix () ; //pour revenir aux valeurs de glFrustum qui est dans reshape (fonction main)
	glMatrixMode(GL_MODELVIEW); 
	//glLoadIdentity(); //le remettre pour test

	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
}

Texture::Texture(int size)
{
	unsigned int *pTexture = NULL;											

	
	pTexture = new unsigned int [size * size * 4]; // 4= 1 pour chaque composant RGBA
	memset(pTexture, 0, size * size * 4 * sizeof(unsigned int));	
	
	
	glGenTextures(1, &textureNumber);								
	glBindTexture(GL_TEXTURE_2D, textureNumber);					
	
	// Cré la texture et la stocke en mémoire vidéo
	glTexImage2D(GL_TEXTURE_2D, 0, 4, size, size, 0, GL_RGBA, GL_UNSIGNED_INT, pTexture);						
	
	// défini la qualité des textures
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	// Since we stored the texture space with OpenGL, we can delete the image data
	delete [] pTexture;																					
}

void Texture::RadialBlur ()
{
	float textureReduction = 0.0 ;
	//glPolygonMode (GL_FRONT, GL_LINE) ;
	glViewport (0,0,128,128); //réduit a la taille du viewport pour que la texture 
						//de l''objet fasse 128x128 sinon l''objet serait rendu dans un espace 
						//plus grand et on prend avec glCopyTexImage2D les 128 premiers
						//pixels.
	
	glDisable(GL_TEXTURE_2D);

	//glutSolidCube (20) ;
	glBegin(GL_QUADS);
		glColor3f(0.0, 1.0, 1.0) ;
		glVertex2f(-10,-10);
		glVertex2f(10,-10);
		glVertex2f(10,10);
		glVertex2f(-10,10);
	glEnd();

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D,textureNumber);			
	
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0); //copie l''objet
														//dans la texture spécifiée en mémoire vidéo
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glViewport(0 , 0,screenWidth ,screenHeight);

	glBindTexture(GL_TEXTURE_2D,textureNumber); //indique que la texture noire va etre utilisée
	
	
	CreateTexture->BlendingOrthoOn() ;
	
	//glDisable (GL_BLEND) ;
//here is the code that seems to be not executed
	glBegin(GL_QUADS) ;					
		for (int num = 0;num <25 ; num++)		
		{
			glColor4f(1.0, 1.0, 1.0, 0.2);	
			glTexCoord2f(0+textureReduction,1-textureReduction);			
			glVertex2f(0,0);				

			glTexCoord2f(0+textureReduction,0+textureReduction);			
			glVertex2f(0,480);				

			glTexCoord2f(1-textureReduction,0+textureReduction);			
			glVertex2f(640,480);				

			glTexCoord2f(1-textureReduction,1-textureReduction);			
			glVertex2f(640,0);				

			textureReduction = textureReduction + 0.02;	
		}
	glEnd();
	CreateTexture->BlendingOrthoOff() ;
}


  
   
Ta texture ne doit-elle pas être d''une puissance de 2 ???

========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Advertisement
it is ever a power of 2 (128x128)otherwise can you tell me of where you are speaking ?

This topic is closed to new replies.

Advertisement