OpenGL

This is a discussion on OpenGL within the Game Programming forums, part of the General Programming Boards category; I'm trying to create a flashbang for my HL mod, but I'm not quite sure how to do this. I ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    OpenGL

    I'm trying to create a flashbang for my HL mod, but I'm not quite sure how to do this. I know which functions I need (I think), but I don't know how to use them properly.

    I want to read in all the pixels on the screen, invert it, and overlay that over whatever is on the screen, with the alpha slowly decreasing. Once its at 0, I want to stop doing this.

    This'd sorta be like the Tom Clancy rainbow six flashbang.

    glReadPixels
    glDrawPixels
    glCopyPixles

    I think I need those three, but how do I modify the alpha?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Are you sure you don't mean gamma? Alpha relates to how opaque or transparent a pixel is. It is a blending factor where the high side will only plot the secondary colored pixel and the low side will only plot the primary colored pixel.

    Secondary and primary are assumed to be 2 separate images.
    Alpha is normally stored in the high order 8 bits of a RGB triple.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    yes, I mean transparency.

    I want it to fade from the image it was before the flashbang (inverted) to clear, but overlay that whole thing (so there's two layers) over the other one

  4. #4
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    you dont have to do that, just raise the gamma to the max, then drop it back down to normal for a flashbang, no reason to invert or modify the rendering anymore than you have to after all.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    I don't want to fade to white.

    I want to have what they saw BEFORE the flashbang (except inverted) slowly fade into what the current view is

    EDIT:

    Code:
    for (int x=0; x<30; x++)
    	{
    		for (int y=0; y<30; y++)
    		{
    			GLfloat pixel[33*3*33*3]; 
    
    			glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT,(GLvoid *)pixel);
    
    			pixel[0] = 255 - pixel[0];
    			pixel[1] = 255 - pixel[1];
    			pixel[2] = 255 - pixel[2];
    
    			glRasterPos2i (x, y); 
    			glDrawPixels (1, 1, GL_RGB, GL_FLOAT, (GLvoid *)pixel);
    		}
    	}
    	return;
    Thats my attempt to do the invert part and then draw it, but that doesn't do anything to the screen. Whats wrong with it?

    Also, there must be a way to do it all at once instead of pixel by pixel... GL_BITMAP, probably, but I have no idea how it works.
    Last edited by Trauts; 01-12-2004 at 06:25 PM.

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    4
    Im no programming expert but i have dabbeld in OpenGL for a wile and modding.

    Just my 2c.

    The code looks ok, but what might be the problem is that its going through that to fast, so you dont see whats on the screen. I reccomend using a timing system to smoothly update the effect on screen over x amount of time.

    ---Brandon

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Well you could get a pointer to the screen and do it in inline assembly. The reason I say assembly language is because you could use MMX to operate on 64-bits at a time thus being able to fade and plot 2 pixels in 32-bit color in very few cycles. MMX also uses saturated arithmetic which means that data types will not overflow or wrap around - not all MMX functions use this, but there are some that do.

    If OpenGL does not natively support what you want to do, my advice would be to use MMX to at least alter the frame buffer and then let GL render it.

    By the way I'm not familiar with GL, but if each of your pixels is composed of RGBA components - hence b+(g<<8)+(r<<16)+(a<<24) - subtracting 255 from the entire pixel value will do nothing. You must operate on each color component, not the whole value to affect the color correctly. Your method looks like it might work in 256 color mode, but thats about it.
    Last edited by VirtualAce; 01-14-2004 at 05:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 11:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21