Thread: Game Programming Effects

  1. #16
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    the parameter doesn't say where to put the r,g,b values. So I would have to know what it is and provide the values?
    src and dst are always one of the constants given in the docs: ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA, etc.
    You don't actually give r,g,b values anywhere, this simply tells allegro (rather, OpenGL) how to draw everything from now until you change the blending again.
    Consider this post signed

  2. #17
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    oh..em I just tried using one of the functions..but allegro doesn't recognize it.
    I tried the allegro function
    set_add_blender(255,0,0) just some rgb value..but nothing is happening
    You ended that sentence with a preposition...Bastard!

  3. #18
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Oh! You must be using Allegro 4, then. If you aren't too far into the project, I'd suggest switching to version 5. There's a big difference in the API but the general idea is the same. Allegro 5 also makes much better use of hardware acceleration. And floating point color triplets .

    In the case of Allegro 4 you'll want to make a call to drawing_mode after setting the blender. Or at least that's what the docs say; I don't believe I ever did transparency in allegro 4.
    Code:
    set_add_blender(255,255,255);
    drawing_mode(DRAW_MODE_TRANS, 0,0,0);
    Consider this post signed

  4. #19
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    yeah, I am using allegro 4. Sorry, should have mentioned that.
    It depends on how you mean by how far..but for my level of game programming I have quite a bit done. Just working on the menu system now.
    Would it take long to modify to allegro 5?

    I will try your idea.but I don't understand how it would know which particle or image i want to blend.
    By the way that paint.NET looks way better than the inbuilt paint software in windows. the interface looks similar though.
    You ended that sentence with a preposition...Bastard!

  5. #20
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Like I said, it blends everything.
    So if you want to use additive blending for one specific particle, you have to set the blending to additive, draw the particle, and then set the blending back to normal. The computer has no concept of particles or any sort of logical representation of an object; it just pushes data through the pipeline and sends it to the monitor. Consider set_add_blender a change in that pipeline.
    Consider this post signed

  6. #21
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    I tried it, but it doesn't appear to do anything.
    Code:
    int main() 
    {
    	allegro_init() ; 
    	set_color_depth(32) ;
    	
    	if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
    	{
    		//allegro_message("Hello") ;
    	}
    	install_keyboard() ;
    	
    	BITMAP *backbuffer = create_bitmap(640,480) ; 
    	clear_bitmap(backbuffer)  ;
    
    	while(!key[KEY_ESC])
    	{
    	
    			rectfill(backbuffer,220,220,320,320,makecol(255,0,0)) ;
    
    			set_add_blender(255,0,0,3);
    				
    			drawing_mode(DRAW_MODE_TRANS, backbuffer,0,0);
    		
    
    			blit(backbuffer, screen, 0,0,0,0,640,480) ; 
    	}
    	
    	  
    	return  0 ; 
    
    }
    END_OF_MAIN()
    the drawing_mode function it accepts a bitmap as a parameter, I just put in backbuffer as I am not sure which.

    Should I post the particle effect code?
    I just want to write a simple program to understand how to use the blending stuff, before I add it to it.
    You ended that sentence with a preposition...Bastard!

  7. #22
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    No, it's working.
    It's just that you can't see it.

    First, you have one object on a black background. Blending is all about the intersection of shapes, and there are none here.
    Second, the object you're drawing already has full intensity for red. It can't get any brighter than that. And it's not going to become white because the other two values are 0.
    For each component, the addition looks something like this:
    R: 0 (black background) + 255 (rectangle) = 255.
    G: 0 (black background) + 0 (rectangle) = 0.
    B: 0 (black background) + 0 (rectangle) = 0.
    So you must either lower the red intensity or add some to green and blue so that the values can add up.

    In
    Code:
    drawing_mode(DRAW_MODE_TRANS, backbuffer,0,0);
    the second argument is for a drawing 'mask'. If the term means nothing to you then it's just as well. Allegro ignores the last 3 arguments for DRAW_MODE_TRANS anyway.

    Also, in
    Code:
    set_add_blender(255,0,0,3);
    I would go with arguments of
    Code:
    set_add_blender(255,255,255,alpha);
    Not that it matters for this case, since you're drawing a red rectangle anyway, but setting the color to (255,255,255) allows all the colors to be seen, in case you have different colored particles. Setting it to (255,0,0) would cause all the particles to appear red. And the last argument is the alpha you want to draw with, the transparency value. In this case, it goes 0-255 just like r,g,b.

    Anyway, here's what I came up with.

    Code:
    #include <allegro.h>
    #include <cstdlib>
    
    int main()
    {
    	int i;
    	allegro_init() ;
    	set_color_depth(32) ;
    
    	if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
    	{
    		//allegro_message("Hello") ;
    	}
    	install_keyboard() ;
    
    	BITMAP *backbuffer = create_bitmap(640,480);
    	clear_bitmap(backbuffer);
    
    	while(!key[KEY_ESC])
    	{
    	        clear_bitmap(backbuffer);
    		drawing_mode(DRAW_MODE_TRANS, 0,0,0);
    
    		set_trans_blender(255,255,255,64);
    
    		srand(0);
    		for (i=0; i<128; i++) {
    			circlefill(backbuffer, 32 + rand()%200,200 + rand()%200, 32, makecol(64,64,64));
    		}
    
    		set_add_blender(255,255,255,64);
    
    		srand(0);
    		for (i=0; i<128; i++) {
    			circlefill(backbuffer, 400 + rand()%200,200 + rand()%200, 32, makecol(64,64,64));
    		}
    
    		blit(backbuffer, screen, 0,0,0,0,640,480) ;
    	}
    
    
    	return  0 ;
    
    }
    END_OF_MAIN()
    Last edited by bernt; 01-16-2011 at 09:37 PM.
    Consider this post signed

  8. #23
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Hey bernt,
    Sorry I fell asleep on you, feeling sick.
    I ran the program and that is a really cool effect, I will try to understand your code and get back to you.
    Really appreciate your help!
    You ended that sentence with a preposition...Bastard!

  9. #24
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    I think i might understand it..
    so you make the vector graphics (or something) transparent, and then you add the blender, to make it have a spotlight effect as you say.
    Does the set_trans_blender() and set_add_blender() need to have the same values?
    I don't think so, once I set the transparency I should be able to change the color values of set_add_blender();?

    I tried it but I still get that same glass color, unless I change the rgb values of circle fill. I tried to make a "fake" pulse. But the transition is too fast.
    Code:
    ////#include [allegro.h]
    ////#include "Vector2.h"
    ////#include [list]
    ////#include [cmath]	
    ////using namespace std;
    ////
    //// int oldspace ;
    //// int spacedown=0 ;
    ////
    //// #define NUMBULLETS 12 
    ////class Bullets
    ////{
    ////public:
    ////	Vector2 pos ;
    ////	bool isAlive ;
    ////
    ////	float xspeed, yspeed;
    ////
    ////	Bullets()
    ////	{
    ////		
    ////		isAlive =false;
    ////	}
    ////
    ////
    ////};
    ////
    //// class Player
    //// {
    //// public:
    ////	 BITMAP *newbuff ;
    ////	 Vector2 velocity ;
    ////	 Vector2 acceleration ; 
    ////	 Vector2 force,look ;
    ////	 float mass ;
    ////	float angle ;
    ////	 float newEnemyX, newEnemyY;
    ////
    ////	Vector2 pos  ;
    ////	Vector2 currPos;
    ////	Bullets bullets[NUMBULLETS];
    ////
    ////
    ////	Player()
    ////	{
    ////		
    ////		angle =0.0f ;
    ////		force.x =0.0f ;
    ////		force.y =0.0f ;
    ////		acceleration.x =0.0f ;
    ////		acceleration.y =0.0f ;
    ////		velocity.x =0.0f ;
    ////		velocity.y=0.0f ;
    ////		mass =0.9f ;
    ////
    ////		newbuff = create_bitmap(20,20) ;
    ////		 clear_to_color(newbuff,makecol(255,0,255)); 
    ////		look.x = 0 ;
    ////		look.y = -1 ;
    ////		pos.x = rand()% 20 ; 
    ////		pos.y = rand() % 400 ;
    ////	}
    ////
    ////	void rotate(float r)
    ////	{
    ////		look.x= sinf(angle*M_PI/180)  ;
    ////		look.y= -cosf(angle*M_PI/180)  ;
    ////	
    ////		
    ////		
    ////		angle+=r; 
    ////		
    ////	}
    ////	void thrust(float units)
    ////	{
    ////		force.x+=look.x*units ;
    ////		force.y+=look.y*units ;
    ////	}
    ////	void movePlayer(float timeDelta)
    ////	{
    ////		acceleration.x = force.x / mass ;
    ////		
    ////		acceleration.y = force.y / mass ;
    ////
    ////		  velocity.x = velocity.x + acceleration.x * timeDelta;
    ////			velocity.y = velocity.y + acceleration.y * timeDelta;
    ////
    ////			pos.x = pos.x + velocity.x * timeDelta;
    ////			pos.y = pos.y + velocity.y * timeDelta;
    ////
    ////			force.x = 0.0f;
    ////			force.y = 0.0f;
    ////
    ////		
    ////	}
    ////
    ////
    ////	~Player()
    ////	{
    ////		destroy_bitmap(newbuff) ;
    ////	}
    //// }	   ;
    ////
    ////  int ticks =0 ;
    ////
    ////  void ticker()
    ////  {
    ////	  ticks++ ;
    ////  }
    ////
    ////
    ////class Particle
    ////{
    ////public:
    ////	BITMAP *newbuff ; 
    ////	Vector2 pos ; 
    ////	Vector2 vel; 
    ////	float angle ;
    ////	int r,g,b;
    ////	float angularVel ; 
    ////	float size ;
    ////	bool isAlive ;
    ////	float TTL ;
    ////	float speed;
    ////	float fade;
    ////	int n ;
    ////	void setPos(float x, float y) 
    ////	{
    ////		pos.x =  x;
    ////		pos.y = y ;
    ////	}
    ////	Particle(float x, float y)
    ////	{
    ////		 n = 0 +rand()% 2 ;
    ////		isAlive =true ;
    ////		switch(n)
    ////		{
    ////		case 0:
    ////			  {
    ////		r=255,g=105,b=180;
    ////		break ;
    ////			  }
    ////			  
    ////		case 1:
    ////			  {
    ////		r=255,g=20,b=147;
    ////		break ;
    ////			  }
    ////		}
    ////
    ////		speed = (float)0.0f+rand()%2 ;
    ////		fade=float(rand()%100)/1000.0f+0.05f;
    ////		angle =0.0f;
    ////		setPos(x,y) ;
    ////		vel.x = 0.0f;
    ////		vel.y = -cos(angle*180/M_PI)*speed ;
    ////		newbuff = create_bitmap(20,20); 
    ////		clear_bitmap(newbuff);
    ////		 clear_to_color(newbuff,makecol(255,0,255));
    ////		TTL =0.8f;
    ////	}
    ////	void Update(float x, float y)
    ////	{
    ////		 switch(n)
    ////		{
    ////		case 0:
    ////			  {
    ////		r=255,g=105,b=180;
    ////		break ;
    ////			  }
    ////			  
    ////		case 1:
    ////			  {
    ////		r=18 ,g=85,b=211;
    ////		break ;
    ////			  }
    ////		}
    ////
    ////		
    ////		pos.x+=vel.x*0.0975f ;
    ////		pos.y+=vel.y*0.0975f;
    ////		
    ////		vel.y*=1.0f;
    ////		angle+=angularVel;
    ////		TTL-=fade;
    ////	
    ////
    ////
    ////		if (TTL[0.05f)	 // If Particle Is Burned Out
    ////	  {
    ////		TTL=0.5f;	 // Give It New Life
    ////		fade=float(rand()%100)/7500 + 0.0075f;	// Random Fade Value
    ////	
    ////		 setPos(x+10,y+20) ;
    ////		speed = (float((rand()%9))+1);
    ////		angle = float(rand()%3 0);
    ////
    ////		vel.x = sin(angle) * speed;
    ////		vel.y = -cos(angle) *speed;
    ////		
    ////	  } 
    ////
    ////	}
    ////	void Draw(BITMAP *backbuffer) 
    ////	{
    ////		circlefill(newbuff,5,5,2,makecol(r,g,b)) ;
    ////		draw_sprite(backbuffer,newbuff,pos.x,pos.y) ;
    ////	}
    ////	   ~Particle()
    ////	   {
    ////		destroy_bitmap(newbuff) ;
    ////	   }
    ////
    ////}
    ////;
    ////
    ////class ParticleEngine
    ////{
    ////public:
    ////	int random ;
    ////	Vector2 emitLoc ;
    ////
    ////	Particle *particles[100] ;
    ////
    ////	ParticleEngine(float x,float y)
    ////	{
    ////		for(int i =0;i[100;i++)
    ////		{
    ////			particles[i] = new Particle(x+10,y+20) ;
    ////		}
    ////	}
    ////	void Update(float x,float y)
    ////	{
    ////		for(int i=0;i[100;i++)
    ////		{
    ////		  
    ////			particles[i]-]Update(x,y) ;
    ////
    ////		}
    ////
    ////	}
    ////	void Draw(BITMAP *backbuffer)
    ////	{
    ////		for(int i=0;i[100;i++)
    ////		{
    ////
    ////			if(particles[i]-]isAlive)
    ////			{
    ////				particles[i]-]Draw(backbuffer) ;
    ////			}
    ////			
    ////		}
    ////	}
    ////}
    ////	
    ////			   ;
    ////int main()
    ////{
    ////	 srand(time(NULL)) ;
    ////	 int n,r,g,b ;
    ////	 n=r=g=b=0 ;
    ////	float	length=0.0f,angle= 90;
    ////	if(!allegro_init())
    ////	{
    ////	
    ////		
    ////		set_color_depth(24) ;
    ////		 PALETTE pallete ;
    ////		 
    ////		BITMAP *obstacle = create_bitmap(100,100) ;
    ////		clear_to_color(obstacle,makecol(0,255,0));
    ////		
    ////		   Player player1 ;
    ////		   Player player2 ;
    ////			Player player3;		  
    ////			 ParticleEngine particleEngine(player1.pos.x,player1.pos.y)  ;
    ////			
    ////	install_keyboard() ;
    ////	
    ////		install_timer() ;
    ////		install_int_ex(ticker, BPS_TO_TIMER( 0));
    ////		  
    ////			
    ////	
    ////									 
    ////
    ////		if(!set_gfx_mode(GFX_AUTODETECT_WINDOWED, 40,480,0,0))
    ////		{
    ////			BITMAP* backbuffer = create_bitmap( 40,480) ;
    ////		
    ////		
    ////			BITMAP *background = create_bitmap( 40,480) ; 
    ////		background = load_bitmap("space.bmp",pallete) ; 
    ////		set_palette(pallete) ;
    ////	
    ////		clear_to_color(backbuffer,makecol(0,0,0));
    ////		
    ////	  
    ////		triangle(player1.newbuff ,0,19,10,0,19,19,makecol(255,255,255));
    ////		 triangle(player2.newbuff,0,19,10,0,19,19,makecol(255,255,255));
    ////		 triangle(player3.newbuff,0,19,10,0,19,19,makecol(255,255,255));
    ////		    	player3.pos.x = 320 ;
    ////				player3.pos.y = 240;
    ////				player3.look.x = 1;
    ////				player3.look.y=0;
    ////			  while(!key[KEY_ESC])
    ////			  {
    ////						n = 0 + rand() % 2 ;
    ////				  switch(n)
    ////		{
    ////		case 0:
    ////			  {
    ////				r=255,g=0,b=0;
    ////				break ;
    ////			  }
    ////		  
    ////		case 1:
    ////			  {
    ////				r=0,g=255,b=0;
    ////				break ;
    ////			  }
    ////		}
    ////				  	//triangle(player1.newbuff ,0,19,10,0,19,19,makecol(0,0,0));
    ////				  
    ////
    ////				  length =(float)sqrt(((player2.pos.x -player1.pos.x)*(player2.pos.x -player1.pos.x)) + ((player2.pos.y -player1.pos.y)*(player2.pos.y -player1.pos.y))  ) ;
    ////				 
    ////				 	 
    ////				  
    ////				  	draw_sprite(backbuffer,background,0,0) ;	
    ////				 
    ////					particleEngine.Update(player1.pos.x,player1.pos.y);
    ////						particleEngine.Draw(backbuffer);
    ////					
    ////					triangle(player1.newbuff,0,19,10,0,19,19,makecol(r,g,b));
    ////					
    ////					triangle(player2.newbuff,0,19,10,0,19,19,makecol(0,0,255));
    ////			
    ////					draw_sprite(background,obstacle,320,100) ;
    ////				 
    ////					player2.newEnemyX = sin((player2.pos.direction(player2.pos-player1.pos))*M_PI/180) ;
    ////						player2.newEnemyY = -cos((player2.pos.direction(player2.pos-player1.pos))*M_PI/180) ;
    ////				   
    ////				
    ////						
    ////						player2.pos.x+=player2.newEnemyX ;
    ////						player2.pos.y+=player2.newEnemyY ;
    ////
    ////					
    ////
    ////					player3.pos.x+=player3.look.x;					
    ////			 		player3.pos.y+=player3.look.y;					
    ////
    ////					  if(player3.pos.x]= 00)
    ////					  {
    ////						  player3.look.x = -player3.look.x; 
    ////						  angle = -angle ;
    ////					  }
    ////					  if(player3.pos.x[=0)
    ////					  {
    ////						  player3.look.x = -player3.look.x; 
    ////						  angle = -angle ;
    ////					  }
    ////
    ////						 
    ////				  
    ////
    ////		   if(key[KEY_RIGHT])
    ////		   {
    ////			 
    ////				player1.rotate(2.0f);   
    ////		   }
    ////
    ////
    ////
    ////		   
    ////		   if(key[KEY_LEFT])
    ////		   {
    ////				player1.rotate(-2.0f);
    ////
    ////		   }
    ////
    ////
    ////		   if(key[KEY_UP])
    ////		   {
    ////
    ////			   
    ////			   
    ////			   player1.thrust(0.07f) ;
    ////				} 
    ////		    
    ////			 if(key[KEY_DOWN])
    ////		   {											 
    ////			 	  player1.thrust(-0.07f) ;
    ////				
    ////		   }
    ////				while(ticks == 0)
    ////		{
    ////			rest(1);//rest until a full tick has passed
    ////		}
    ////
    ////		while(ticks ] 0)
    ////		{
    ////			int old_ticks = ticks;
    ////
    ////			ticks--;
    ////			if(old_ticks [= ticks)//logic is taking too long: abort and draw a frame
    ////				break;
    ////		}
    ////		  
    ////			 
    ////	player1.movePlayer(0.4f) ;	  
    ////			
    ////	rotate_sprite(backbuffer,player3.newbuff,player3.pos.x,player3.pos.y,ftofix(angle*250/3 0)) ;		
    ////	rotate_sprite(backbuffer,player1.newbuff,player1.pos.x,player1.pos.y,ftofix((player1.angle) *2 /3 0)) ;
    ////	rotate_sprite(backbuffer,player2.newbuff,player2.pos.x ,player2.pos.y,ftofix((player2.pos.angle)*2 /3 0)) ;				 
    ////			    
    ////	
    ////
    ////textprintf_ex(backbuffer,font,320,20,makecol(255,255,255),-1,"Player2  Distance y: %f", player2.pos.angle) ;
    ////				
    ////				
    ////				blit(backbuffer,screen,0,0,0,0,SCREEN_W,SCREEN_H) ;
    ////
    ////				clear_bitmap(backbuffer) ; 
    ////
    ////
    ////			  }		  						
    ////			destroy_bitmap(backbuffer) ;
    ////			destroy_bitmap(background) ;
    ////		}
    ////			
    ////	}
    ////
    ////	return 0 ;
    ////}
    ////
    ////
    ////END_OF_MAIN()
    ////
    //
    //#include <math.h>
    //#include <allegro.h>
    //struct Color
    //{
    //	int r,g,b; 
    //}color[4];
    //void delay() ; 
    //void resetColors() ;
    //void delay(Color &) ; 
    //int main() 
    //{
    //	allegro_init() ; 
    //	set_color_depth(32) ;
    //	
    //	if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
    //	{
    //		//allegro_message("Hello") ;
    //	}
    //	install_keyboard() ;
    //	
    //	BITMAP *backbuffer = create_bitmap(640,480) ; 
    //	clear_bitmap(backbuffer)  ;
    //
    //	while(!key[KEY_ESC])
    //	{
    //	
    //			rectfill(backbuffer,220,220,320,320,makecol(255,0,0)) ;
    //
    //			set_add_blender(255,0,0,3);
    //				
    //			drawing_mode(DRAW_MODE_TRANS, backbuffer,0,0);
    //		
    //
    //			blit(backbuffer, screen, 0,0,0,0,640,480) ; 
    //	}
    //	
    //	  
    //	return  0 ; 
    //
    //}
    //END_OF_MAIN()/*
    //			 			
    //			/*delay() ;
    //			delay(color[1]) ;
    //			line(backbuffer,320,106,400,106,makecol(color[2].r,color[2].g,color[2].b)); 
    //			delay()  ;
    //			delay(color[2]) ;
    //			line(backbuffer,320,142,400,142,makecol(color[3].r,color[3].g,color[3].b)); 
    //			delay() ; 
    //	
    //	int r = 255 ; 
    //	int g = 0 ; 
    //	int b=0;
    //	int r1 = 0, r2 = 0, r3 = 255 ;
    //	color[0].r =255,color[0].g=0,  color[0].b=0;			
    //	color[1].r =0,color[1].g=0,  color[1].b=255;			
    //
    //void delay()
    //{
    //	unsigned int i=0;
    //	while( i < 100000) 
    //	{
    //		for(int j=0;j<10000;j++)
    //		{
    //		}
    //		i++ ;
    //	}
    //}*/
    //
    //void delay(Color &color)
    //{
    //	
    //
    //	color.r=0;
    //	color.g =0 ;
    //	color.b =255;
    //
    //}
    //
    //	/*
    //				color[2].r= 255 ; 
    //			color[2].g=0;
    //			color[2].b=0;
    //			delay() ;
    //
    //			color[1].r= 255 ; 
    //			color[1].g=0;
    //			color[1].b=0;
    //			delay() ;
    //
    //			color[0].r= 255 ; 
    //			color[0].g=0;
    //			color[0].b=0;
    //			
    //		line(backbuffer,320,109,400,109,makecol(r,g,b)); 
    //			line(backbuffer,320,112,400,112,makecol(255,0,0)); 
    //			line(backbuffer,320,115,400,115,makecol(255,0,0)); 
    //			line(backbuffer,320,118,400,118,makecol(255,0,0)); 
    //			line(backbuffer,320,121,400,121,makecol(255,0,0)); 
    //			line(backbuffer,320,124,400,124,makecol(255,0,0)); 
    //			line(backbuffer,320,127,400,127,makecol(255,0,0)); 
    //			line(backbuffer,320,130,400,130,makecol(255,0,0)); 
    //			line(backbuffer,320,133,400,133,makecol(255,0,0)); 
    //			line(backbuffer,320,136,400,136,makecol(255,0,0)); 
    //			line(backbuffer,320,139,400,139,makecol(255,0,0)); 
    //			*/
    //
    //
    //
    //
    //
    //
    //
    //
    //
    //
    //
    //
    //
    //		
    //	// int r=0,g=0,b=0,x=0,y=0;
    //	// float angle =0.0f ;
    //	//BITMAP* buffer;
    //	//BITMAP *spacePic ;
    //	//void moveShip() ; 
    //	//struct Particle_Type
    //	//{
    //	//  double x;
    //	//  double y;
    //	//  double speed;
    //	//  double angle;
    //	//  int life;
    //	//}Particles[150];
    //	// 
    //	//double Max_Angle = 2 * 3.14159;
    //	// 
    //	//void Draw_Stuff()
    //
    //	//{
    //	//	
    //	//	
    //	//  clear_to_color(buffer, makecol(0, 0, 0));
    //	//  
    //	//  for(int i = 0; i< 150; i++)
    //	//  {
    //	//    if(Particles[i].life)
    //	//    {  
    //	//      putpixel(buffer, Particles[i].x, Particles[i].y, makecol(r, g, b));
    //	//    }
    //	//	r++,g++,b++ ;
    //	//	if(r>=255)
    //	//	{
    //	//		r=0 + rand()%255 ;
    //	//		
    //	//		
    //	//	}
    //	//	if(g>=255)
    //	//	{
    //	//		
    //	//		g=r + rand()%b ;
    //	//	
    //	//	}
    //	//		if(b>=255)
    //	//	{
    //	//		
    //	//		b=r + rand()%g ;
    //	//	
    //	//	}
    // //	  }
    //	//  
    //	//  rotate_sprite(buffer,spacePic,x,y,ftofix(angle)); 
    //	//  //masked_blit(spacePic, buffer,0,0,0,0,spacePic->w,spacePic->h);
    //	//  textprintf(buffer,font,320,10,makecol(255,0,0),"R: %d G: %d B: %d", r,g,b) ;
    //	//  blit(buffer, screen, 0, 0, 0, 0,640, 480);
    //	//}
    //	// 
    //	//int main()
    //	//{
    //	//	srand(time(NULL)) ;
    //	//  if(!allegro_init())
    //	//  {
    //	//	   //allegro_message("Hello") ;
    //	//  }
    //	//  
    //	//  set_color_depth(16);
    //	//  if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
    //	//  {
    //	//	  //allegro_message("Hello") ;
    //	//  }
    // //	   install_keyboard();
    //	//  buffer = create_bitmap(640, 480);
    //	//  
    //	//  spacePic = load_bitmap("ship2.bmp", NULL) ; 
    //	//  //clear_to_color(spacePic, makecol(255, 0, 255));
    //	//  while(!key[KEY_ESC])
    //	//  {
    //	//    if(key[KEY_SPACE])
    // //   {
    //	//      for(int i = 0; i < 150; i++)
    //	//      {
    //	//        Particles[i].x = 320.0;
    // //	        Particles[i].y = 240.0;
    //	//        Particles[i].speed = rand() % 10 + 5;
    //	//        Particles[i].angle = rand() % 360 + 1;
    //	//        Particles[i].angle = Particles[i].angle * 3.14159 / 180;
    //	//        Particles[i].life = rand() % 10 + 10;
    //	//      }
    //	//    }
    //	//    for(int i = 0; i < 150; i++)
    //	//    {
    //	//      if(Particles[i].life > 0)
    // //	      {
    //	//        Particles[i].x += Particles[i].speed * cos(Particles[i].angle);
    //	//        Particles[i].y += Particles[i].speed * sin(Particles[i].angle);
    //	//        Particles[i].life--;
    // //      }
    //	// }
    //	//	moveShip() ;
    //	//	
    // //	    Draw_Stuff();
    //	//	
    // //	    rest(50);
    // //	  }
    // //	  destroy_bitmap(buffer);
    //	//  destroy_bitmap(spacePic);
    // // 	  allegro_exit();
    //	//  return 0 ;
    //	//}
    //	//void moveShip()
    //	//{
    //	//	if(key[KEY_UP])
    //	//	{
    //	//				 --y ;
    //	//	}
    //	//	
    //	//	if(key[KEY_DOWN])
    //	//	{
    //	//				 ++y ;
    //	//	}
    //	//	if(key[KEY_LEFT])
    //	//	{
    //	//		angle-=1.0f; 
    //	//	}
    //	//	
    //	//	if(key[KEY_RIGHT])
    //	//	{
    //	//		angle+=1.0f; 
    //	//	}
    //	//}
    
    #include <allegro.h>
    #include <cstdlib>
    
    int main()
    {
    	int i;
    	allegro_init() ;
    	set_color_depth(32) ;
    	float r=64.0f,g=64.0f,b=64.0f ;
    	if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
    	{
    		//allegro_message("Hello") ;
    	}
    	install_keyboard() ;
    	bool lock = false;
    	BITMAP *backbuffer = create_bitmap(640,480);
    	clear_bitmap(backbuffer);
    
    	while(!key[KEY_ESC])
    	{
    	    clear_bitmap(backbuffer);
    		drawing_mode(DRAW_MODE_TRANS, 0,0,0);
    
    		set_trans_blender(255,255,255,64);
    
    
    		srand(0);
    	
    		for (i=0; i<128; i++) {
    			circlefill(backbuffer, 32 + rand()%200,200 + rand()%200, 32, makecol(64,64,64));
    		}
    
    		set_add_blender(255,255,255,64);
    
    		srand(0);
    		
    		for (i=0; i<128; i++) {
    			circlefill(backbuffer, 400 + rand()%200,200 + rand()%200, 32, makecol(r,g,b));
    		}
    
    		
    		if(!lock)
    		{
    
    			for(int i=0; i< 100; i++)
    			{
    				for(int g=0;g<100;g++)
    				{}
    			}	   
    			r+=0.1f;
    			g+=0.1f ;
    			b+=0.1f  ;
    		   if(r>70)
    			   lock = true ;
    		}
    		else
    		{
    			
    			r-=0.1f ;
    			
    		   g-=0.1f		;
    		   b-=0.1f ;
    		     if(r<64)
    			   lock = false ;
    		}
    		
    		
    
    
    		blit(backbuffer, screen, 0,0,0,0,640,480) ;
    	}
    
    
    	return  0 ;
    
    }
    END_OF_MAIN()
    Maybe you can have a look at it thanks. I will keep trying to do it.
    You ended that sentence with a preposition...Bastard!

  10. #25
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    wtf!! :S
    I didn't realize I posted all the code, and I can't edit.
    The code I am looking at starts where the comments end (mmn I guess that is kind of obvious, but just in case it makes you want to run away ).
    You ended that sentence with a preposition...Bastard!

  11. #26
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    so you make the vector graphics (or something) transparent, and then you add the blender, to make it have a spotlight effect as you say.
    Does the set_trans_blender() and set_add_blender() need to have the same values?
    I don't think so, once I set the transparency I should be able to change the color values of set_add_blender();?
    Looking at what I posted:
    Code:
    drawing_mode(DRAW_MODE_TRANS, 0,0,0);
    
    set_trans_blender(255,255,255,64);
    
    srand(0);
    for (i=0; i<128; i++) {
    	circlefill(backbuffer, 32 + rand()%200,200 + rand()%200, 32, makecol(64,64,64));
    }
    
    set_add_blender(255,255,255,64);
    
    srand(0);
    for (i=0; i<128; i++) {
    	circlefill(backbuffer, 400 + rand()%200,200 + rand()%200, 32, makecol(64,64,64));
    }
    The first line tells Allegro to take transparency into account.
    Then, I set the blender to a normal transparency and draw the circles on the left. (32 + rand)
    Then, I set the blender to additive and draw the circles on the right. (400 + rand)

    You don't really need the part where I do set_trans_blender and draw circles on the left, it was just for comparison between normal transparency and additive.

    ---
    Code:
    float r=64.0f,g=64.0f,b=64.0f ;
    ...
    makecol(r,g,b)
    ...
    r+=0.1f;
    g+=0.1f ;
    b+=0.1f  ;
    if(r>70)
        lock = true ;
    r,g,b should be ints as that is what makecol takes for arguments.
    Consider this post signed

  12. #27
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    yeah I figured it was for comparing.. One thing I noticed is that i need to have the circles overlay each other or the light effect won't occur..

    i know it takes ints but I was trying to make it pulse slowly, and was hoping that increase by 0.1 and decreasing by 0.1f might have that effect...

    It didn't
    You ended that sentence with a preposition...Bastard!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. So you want to be a game programmer?
    By dxfoo in forum Game Programming
    Replies: 23
    Last Post: 09-26-2006, 08:38 AM
  3. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  4. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM