Main Menu

Filter Effects

Started by Damian3395, June 08, 2014, 22:30:35

Previous topic - Next topic

Damian3395

So I'm writing a class that displays a filter over all the images rendered onto my screen. To give my game a more fun effect. So far I have created a flickering effect, which I feel like could be better, it's suppose to feel like a tv that's screen is flickering on and off because its half way broken. My code:

public void initFlicker(){
		flick = false;
		alpha = 1.0f;
		currentTime = getTime();
		flickerTime = getTime();
		random = new Random();
		flickerCount = random.nextInt(10);
		waitPeriod = new int[flickerCount];
		flickerPeriod = new int[flickerCount];
		count = 0;
		flickerRest = random.nextInt(5) + 2;
		for(int i = 0; i < flickerCount; i++){
			waitPeriod[i] = (random.nextInt(10) + 1) * 10;
			flickerPeriod[i] = (random.nextInt(10) + 1) * 10;
		}
	}
	public void renderFlicker(){
		long time = getTime();
		deltaTime = (time - currentTime)/1000;
		
		if(deltaTime >= flickerRest){
			if(count < flickerCount){
				if(flick){
					//flickerPeriod
					if((getTime() - flickerTime) < flickerPeriod[count]){
						flick();
					}else{
						flickerTime = getTime();
						count++;
						flick = false;
					}
				}else{
					if((getTime() - flickerTime) > waitPeriod[count]){
						flickerTime = getTime();
						flick = true;
					}
				}
			}else{
				//Reset Flicker
				count = 0;
				flickerCount = random.nextInt(10);
				waitPeriod = new int[flickerCount];
				flickerPeriod = new int[flickerCount];
				for(int i = 0; i < flickerCount; i++){
					waitPeriod[i] = (random.nextInt(10) + 1) * 10;
					flickerPeriod[i] = (random.nextInt(10) + 1) * 10;
				}
				flickerRest = random.nextInt(5) + 2;
				currentTime = getTime();
			}
		}
	}
	
	private void flick(){
		GL11.glDisable(GL11.GL_TEXTURE_2D);
		
		GL11.glColor4f(0.0f, 0.0f, 0.0f, alpha);
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glVertex2i(x, y);
			GL11.glVertex2i(x + width, y);
			GL11.glVertex2i(x + width, y + height);
			GL11.glVertex2i(x, y + height);
		GL11.glEnd();
		
		GL11.glEnable(GL11.GL_TEXTURE_2D);
	}


Anyone have any tips or ideas on how to improve my code. Thanks.

Also, I'm trying to make a static screen that creates random lines across that move down to the bottom of the screen and only shows a small part of the center of the screen. I attached a png file to show what I would like it to look like.

Hanksha

I think you should look on gl shader language, it will allow you to do those kind of effect very easily.