Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


OpenGL Plasma in Opengl Help(Not sine)

This topic is 5356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to convert some pygame plasma code to Opengl. However I cannot figure out how to do a getpixel command in Opengl. Any guides, help or directions will be appreciated. Here is the pygame code : import pygame, sys from Numeric import * from RandomArray import * import random # Global Values ScreenRes=array((640,480)) global screen global color #global colorarray pygame.init() screen=pygame.display.set_mode(ScreenRes,0,8) #screen.set_palette([[0,0,0],[0,255,0],[255,255,255]]) #we will use this to setup our palette for plasma def ramp(rs,re,gs,ge,bs,be,startcol,endcol): n=1 nadd=int(255/(endcol-startcol)) for i in range(startcol,endcol): r=int((((rs-re)*n)/255)+re) g=int((((gs-ge)*n)/255)+ge) b=int((((bs-be)*n)/255)+be) screen.set_palette_at(i,[r,g,b]) n=n+nadd # #Rotate the palette # def rotatepalette(): y=screen.get_palette() y = list(y) for s in range(254): x = y.pop(1) y.append(x) screen.set_palette(tuple(y)) pygame.display.update() # #Put down the starting points # def startplasma(x0,y0,x1,y1): screen.lock() screen.set_at((x0,y0),(random.randint(0,255)+1)) screen.set_at((x1,y0),(random.randint(0,255)+1)) screen.set_at((x0,y1),(random.randint(0,255)+1)) screen.set_at((x1,y1),(random.randint(0,255)+1)) screen.unlock() # #Calculate the new color # def newcolor(x0,y0,x,y,x1,y1): # c=screen.get_at((x,y)) if screen.get_at((x,y)) <> (0,0,0,255): return() color=(x1-x0)+(y1-y0) color=random.randint(0,(color*2))-color a=screen.map_rgb(screen.get_at((x0,y0))) b=screen.map_rgb(screen.get_at((x1,y1))) color=color+int((a+b+1)/2) if color < 1: color=1 elif color > 254: color=254 screen.set_at((x,y),color) # #Do the actual plasma calculations # #START PROCEDURE doblock def doblock(x0,y0,x1,y1): if ((x1-x0)<2) and ((y1-y0)<2): return() x=int((x0+x1+1)/2) y=int((y0+y1+1)/2) newcolor(x0,y0,x,y0,x1,y0) newcolor(x1,y0,x1,y,x1,y1) newcolor(x0,y1,x,y1,x1,y1) newcolor(x0,y0,x0,y,x0,y1) a=screen.map_rgb(screen.get_at((x0,y0))) b=screen.map_rgb(screen.get_at((x1,y0))) c=screen.map_rgb(screen.get_at((x1,y1))) d=screen.map_rgb(screen.get_at((x0,y1))) e=2 color=int((a+b+c+d+e)/4) screen.set_at((x,y),color) doblock(x0,y0,x,y) doblock(x,y0,x1,y) doblock(x,y,x1,y1) doblock(x0,y,x,y1) #END PROCEDURE doblock ramp(255,000,000,000,000,000,1,63) ramp(000,255,000,000,000,000,63,126) ramp(000,000,255,000,000,255,126,189) ramp(000,000,000,255,000,000,189,256) #while 1: # for event in pygame.event.get(): # if event.type == pygame.QUIT: # sys.exit() x0=0 y0=0 x1=639 y1=479 startplasma(x0,y0,x1,y1) doblock(0,0,639,479) pygame.display.update() while 1: rotatepalette() for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() It takes a while to draw the plasma on slower systems. This is the reason why I want to port it to Opengl. (Pardon the english, it is not my native language) All of us were put on earth to do a certain amount of work. I am so far behind I will never die.

Share this post

Link to post
Share on other sites
First, this belongs to the OpenGL forum, not the graphics forum.
Second, there are no functions in OpenGL for getting and setting individual pixels (IIRC), since that is extremely inefficient, and further OpenGL was not meant to be a 2D API (although it can be used as such). There are, however, function for getting and setting a rectagle of pixels, glGet/SetPixels or some such thing.
And finally, it is highly unrecommended to read anything back from the hardware, since it is very slow. Instead, you should keep a copy of the plasma image in system memory, update it as normal, and then blit to the hardware buffer with glSetPixels (or whatever its name is). Other than that, you can try to put the plasma calculations in a pixel shader, but those are usually not available on low-end systems.

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"

We come in peace... surrender or die!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!