How to create an under water effect in blitzmax?

BlitzMax Forums/BlitzMax Programming/How to create an under water effect in blitzmax?

Takis76(Posted 2015) [#1]
Hello my friends,

I am progressing my game very well.
Look some videos and screenshots at :

https://facebook.com/darklordbeholder


Now I am looking some way to make an underwater effect.
I found in the forums this:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1693

My game will have some underwater levels and I would like to do the same effect but the code was written in blitz3d.

Is it possible the effect being implemented not in full screen but only in rectangular area of a 2D screen, but there are not 3D objects and camera.
For example the dungeon viewport. (A part of a 2D screen).

Any nice idea?

Thank you very much.


*(Posted 2015) [#2]
A simple load the images as pixel high slices as a animimage then use a sine wave with a little randomness applied to the radius.


Derron(Posted 2015) [#3]
AnimImage slices the image into various textures. So you better use a custom "drawSubImageRect"-thing to avoid texture-switches.


bye
Ron


Takis76(Posted 2015) [#4]

A simple load the images as pixel high slices as a animimage then use a sine wave with a little randomness applied to the radius.



What you mean saying high slices? Would you like to give me an example.

Something like 1 long pixel vertical Marquez in advertisement signs?


Derron(Posted 2015) [#5]
He talks about this:
If your image is 100x50 pixels, you load it as an anim image with 100 frames, each 1x50 pixels.

Now when you draw your "wave" you draw it in a loop, advancing "x" by 1 for each frame. The y is then displaced with a sin() (whose param is containing "x").


With "drawsubimageract" you do something similar, but instead of using "frames" you advance the subimage-rect by 1 pixel (so you draw the same image 100 times, but each time the "rect" advances by 1 pixel. the rect is of course also 1x50 in size).


bye
Ron


Takis76(Posted 2015) [#6]
Do I need to capture the image in real time? Because this image is not a static image is the viewport of the dungeon which always changes when players moving.

How do I will capture a portion of the screen to create this image.

My image will be , 352x240. So the sub images will be 1x240 according to your example. But the image must be captured on runtime.

I will try to experiment with this idea.


Derron(Posted 2015) [#7]
For such effects you should consider some "render to texture" approach.

Also have a look for "GLSL" / shaders with BlitzMax ... think easiest way is with Bruceys SDL-wrapper - and/or BMX-NG + Mojo2. Or do things on your own with OGL.



bye
Ron


Takis76(Posted 2015) [#8]
OK Now I will try to implement the effect.

First I will use the function GrabPixmap.


Global Underwater_image:TPixmap

Underwater_image = GrabPixmap(23, 68, 352, 240)

DrawPixmap(Underwater_image, 23, 68)




This just copy whole image.

Or do I need to create an array of images


Global Underwater_image:TPixmap[352]

For x=1 to 352
     Underwater_image[x] = GrabPixmap(22+x, 68, 1+x, 240)
next

DrawPixmap(Underwater_image, 22+x, 68)


I tried to copy the pixmap image and the image was black.


Derron(Posted 2015) [#9]
Just try and find out on your own.

local img:TImage = LoadImage( GrabPixmap(...) )

For local x:int = 1 to 352
DrawSubDrawSubImageRect( image, 22 + x, 68 + amplitudeScaling * sin(x * waveLengthScaling), 1, 240, 1, 240, x, 0, 1, 240)
Next

(above is untested, so params might need adjustment)


PS: if you did not buy the licence for "Eye of the beholder" I would strongly suggest to rename the game ... and not to provide copyrighted assets with your binaries.


bye
Ron


Takis76(Posted 2015) [#10]
I have already asked Wizards of the Coast and they don't care about , because the game is not Magic the Gathering. The name Eye of the Beholder is very generic. Is something similar to say , the leg of the chair for example. So there are no special words which need to be registered.
The engine is created from scratch so I have the copyrights , the graphics program I use is Corel Paint Shop pro which is genuine (I have purchased it) The programming language is blitzmax which is genuine too. Some of musics were created with keyboard and from music composers and the sound effects were created with microphone.

About the graphics , have changed them a lot and more new graphics were created. Also graphics designers design and new graphics too. :) and when my indiegogo campaign will finish , I will hire more graphics designers who will create more new graphics. Even if I will change the title from "Eye of the Beholder" to "The Eye of the Beholder" this changes the title too. But Wizards they don't care.

I will try your code and I will tell you if the effect was successful.
Thank you :)


*(Posted 2015) [#11]
yeah eye of the beholder is a common phrase, the original game uses a trademark to keep the images etc of the game separate from everyone elses.

One thing you cant draw from is linking it to the old one that is a no-no unless you get permission from them.


Derron(Posted 2015) [#12]
The last house on the left ... is also a common phrase, but you might get into trouble bringing a movie with this title to the cinemas.


If you asked them ... less things to worry, albeit there might be someone else claiming ownership of the "title" (if it is registered).

It does not matter to me what kind of programme you used - if you have done the gfx, then there shouldn't be problems lurking around.
Same for sfx.


If you use OGL instead of DX there are less cpu-hungry approaches to your water effect (shaders / render2texture) ...


bye
Ron


Takis76(Posted 2015) [#13]
I did something:


	Underwater_image = LoadImage("some_image.png", MASKEDIMAGE)


	If (Current_time >= Underwater_Effect.Deadline_time) Then
	Underwater_Effect.Time_Delay = 80
	Underwater_Effect.Deadline_time = Current_time + Underwater_Effect.Time_Delay
		
	amplitudeScaling = Rnd(1, 2)
	waveLengthScaling = Rnd(3, 6)
		
	EndIf

	For Water_x = 1 To 352
	DrawSubImageRect(Underwater_image, 322 + Water_x + amplitudeScaling * Sin(Water_x * waveLengthScaling), 268, 20 + amplitudeScaling * Sin(Water_x * waveLengthScaling), 240, 1 + Water_x, 1, 20, 240, 1, 1, 0)
	Next





The code above loads some image and does the water wave effect.
The only problem is , how to capture the image on run time.
The grabpixmap is very slow.

I am looking how to capture a rectangular area of the screen and store it to an image but with fast way.


Derron(Posted 2015) [#14]
You aren't the first requesting a fast "manipulate whats drawn on screen" approach:

- use a shader
- render your scenery to a texture and manipulate the texture then
- use some kind of overlay (slight blueish, some "bubbles" moving from bottom to top ...)

The last one is some "circumvention" as it just tries to avoid the advanced things.
Having "shaders" allows for blurring the the screen, tinting ... and of course rippling water fx. But this is then something I do not know. If there comes one up with a "dx + opengl" solution for blitzmax - I will listen.


bye
Ron


Takis76(Posted 2015) [#15]
I don't know nothing about shaders and how to draw graphics over textures :(


Takis76(Posted 2015) [#16]
Any Idea where do I will find Brucey's SDL-wrapper or how to use shaders?


Derron(Posted 2015) [#17]
shaders: forum search
sdl: bmx-ng - https://github.com/bmx-ng (brucey also has a subforum here in this forum).


bye
Ron


Takis76(Posted 2015) [#18]
Did anyone have errors when tried to compile the mod?
I put the mod in the mods directory in blitzmax with sdl.mod directory

I use Blide to compile the new mods and I have compiled lots of mods without problem.
This one generates compile errors.

►►►ERRORsdl.d3d9sdlgraphics was not built
Compile Error: Can't find interface for module 'sdl.sdlgraphics'
[C:/BlitzMax/mod/sdl.mod/d3d9sdlgraphics.mod/d3d9sdlgraphics.bmx;8;1]
Build Error: failed to compile C:/BlitzMax/mod/sdl.mod/d3d9sdlgraphics.mod/d3d9sdlgraphics.bmx

And other similar errors in 13 mod files.


Brucey(Posted 2015) [#19]
Hallo. I don't recommend trying to integrate your large project with NG and SDL.
Stick with the stuff you are currently using and don't get side tracked...


Takis76(Posted 2015) [#20]
Hello Brucey,

I had the same thought. I just want to implement an underwater effect and then , Derron kindly suggested shaders and other stuff , I don't understand. I have seen shaders and are nice , but I don't know how to program them and I don't know how to render them in blitzmax.

My project is huge and converting everything to SDL is a huge work (Your mod doesn't compiles),and my project is more than 120.000 lines of code and I need to break lots of things and change my whole engine.

I found one code from code archives about ccCopyImageRect() function which copies portion of one image to another to do faster image captures because the default GrabPixmap() function is veryyyyyyyy slowwwwwwwwwwww. But the copyimagerect() is faster , but it destroys all of my transparent images.

This one:
Function ccCopyImageRect(Source:TImage, SX:Int, SY:Int, SWidth:Int, SHeight:Int, Dest:TImage, DX:Int, DY:Int)
	
	'get the pixmap for the images
	Local SourcePix:TPixmap = LockImage(Source)
	Local DestPix:TPixmap = LockImage(Dest)
	
	'find the dimentions
	Local SourceWidth:Int = PixmapWidth(SourcePix)
	Local SourceHeight:Int = PixmapHeight(SourcePix)
	Local DestWidth:Int = PixmapWidth(DestPix)
	Local DestHeight:Int = PixmapHeight(DestPix)
	
	If SX < SourceWidth And SY < SourceHeight And DX < DestWidth And DY < DestHeight 'make sure rects are on image
		If SX+SWidth > SourceWidth Then SWidth = SourceWidth - SX 'bound the coordinates to the image area
		If SY+SHeight > SourceHeight Then SHeight = SourceHeight - SY
		If DX+SWidth > DestWidth Then SWidth = DestWidth - DX 'Make sure coordinates will fit into the destination
		If DY+SHeight > DestHeight Then SHeight = DestHeight - DY
		
		'find the pitch
		Local SourcePitch:Int = PixmapPitch(SourcePix)
		Local DestPitch:Int = PixmapPitch(DestPix)
	
		'pointers To the first pixel of pixmaps
		Local SourcePtr:Byte Ptr = PixmapPixelPtr(SourcePix) + SY * SourcePitch + SX * 4
		Local DestPtr:Byte Ptr = PixmapPixelPtr(DestPix) + DY * DestPitch + DX * 4
		
		'copy pixels over one line at a time
		For Local i:Int = 1 To SHeight
			MemCopy(DestPtr,SourcePtr,SWidth*4)
			SourcePtr :+ SourcePitch
			DestPtr :+ DestPitch
		Next
	End If
	
	'unlock the buffers
	UnlockImage(Source)
	UnlockImage(Dest)
End Function



The SetMaskColor(255, 0, 255) is not working anymore and even if I will make the image transparent , it replaces all transparent pixels to white.

If you have some nice idea how to grab a portion of image fast and paste it on the screen or on other image buffer without destroying the transparency.


Galdy(Posted 2015) [#21]
I don't know if this would work at all, but Is memory at such a premium you couldn't just make a water distortion animation series of images at 352x240 and use transparency? You're talking what, maybe around 5 megs for say 15 frames? You could break up the images into smaller blocks to try to reduce memory usage.


Takis76(Posted 2015) [#22]
I have sliced the images to 1x240
352 images of 1x240

But the problem is not pasting the images , is the grabbing the portion of screen
to update always the viewport of the dungeon when players walking and the water effect always render.


Galdy(Posted 2015) [#23]
So you are trying to use one image i take it, but manipulate it with code to create the distortion. Thus slicing the one image up as others have suggested to manipulate it. I don't understand your grab image technique or why that is necessary. Something to do with pixmaps I take it? Something I've never played with. Why not just pre-crop the image into slices and load in the slices? Wouldn't that do away with all that pixmap/copy code? Just a curious amateur here.


FBEpyon(Posted 2015) [#24]
@Takis76

Try something like this :



Edit : Here is the modification needed to make it remove color mask.


	For Local x:Int = 0 Until sw
	For Local y:Int = 0 Until sh
	
		If argb[x + y * sw] <> 255 Shl 24 | 255 Shl 16 | 0 Shl 8 | 255
	
		WritePixel pix, x, y, argb[x + y * sw]
		
		EndIf
	
	Next
	Next



I'm not sure if this is what you are trying to do, but it works for the things I do, and it has changed over time, but you can modify it for what you are trying to do. Look at the function, and see if you are able to modify it for what you are trying to do.

Here is another form of what you might be trying to do:



FBEpyon


Takis76(Posted 2015) [#25]
When I want to update my underwater effect , I just want to grab a portion rectangle of the screen and I store it to an image TImage and then draw it again , in the same position.

This updates the dungeon viewport with the underwater effect.
The grabbing with grabpixmap is very slow.

The grabscreen code you gave freezes my program.

The GrabImageRect code you gave is nice , but grabs a portion of loaded image from file not screen. I like this code , but is for another use. Is nice for cut sprites from a sprite sheet.

I just want to cut the portion of screen , store it to an image buffer, no file and re paste this grabbed image again fast.

:)


FBEpyon(Posted 2015) [#26]
Yeah I wasn't sure how good the second one was going to be. Glreadpixel is good for what you are doing, but not sure how to help without having it like u have it.

Can you post a quick sample code of how you are using my grabscreen code?


Takis76(Posted 2015) [#27]
Yes.

In my game I present whole interface with the dungeon viewport.

In my old code first I have one function which initializes this image. I used the
GrabPixmap() function.

First I prepare all global variables somewhere at the beginning of the program.

Global Water_x:Int
Global amplitudeScaling:Int
Global waveLengthScaling:Int
Global Underwater_pixmap:TPixmap


Then I was created an empty pixmap and I was run the initialization function, just
after all game data was loaded.

Function Init_Underwater_Effect()

Underwater_pixmap = GrabPixmap(23, 68, 352, 240)
End Function


This initialization creates an empty pixmap with name Underwater_pixmap.

After this in the main game loop which the dungeon was rendered I call this function
continuously.

Function Draw_Underwater_Effect()

	Underwater_pixmap = GrabPixmap(23, 68, 352, 240)
	Underwater_image = LoadImage(Underwater_pixmap, MASKEDIMAGE)

	
	If (Current_time >= Underwater_Effect.Deadline_time) Then
	Underwater_Effect.Time_Delay = 80
	Underwater_Effect.Deadline_time = Current_time + Underwater_Effect.Time_Delay
	
	
			
	amplitudeScaling = Rnd(1, 4)
	waveLengthScaling = Rnd(4, 8)
		
	EndIf

	For Water_x = 1 To 352
	DrawSubImageRect(Underwater_image, 423 + Water_x + amplitudeScaling * Sin(Water_x * waveLengthScaling), 69, 20 + amplitudeScaling * Sin(Water_x * waveLengthScaling), 240 + amplitudeScaling * Sin(waveLengthScaling), 1 + Water_x, 1, 20, 240, 1, 1, 0)
	Next


End function


Grabbing the pixmap and load the image from the pixmap in the main game loop and do this continuously slows down the game.

The new grabbed image draws on the screen with DrawSubImageRect() function to make the underwater effect.

After this , I have only 5 Frames Per Second.

Try to load your own image on the screen and run my code to see the effect.


Takis76(Posted 2015) [#28]
I have posted a quick example to see the effect.


SuperStrict

Import brl.PNGLoader

Global graph:TGraphics = Graphics(640, 480, 0, 120)
Global Underwater_pixmap:TPixmap
Global Water_x:Int
Global amplitudeScaling:Int
Global waveLengthScaling:Int

Global Sample_Image:TImage
Global Underwater_image:TImage
Global Current_time:Int

Type My_Underwater_Effect

	Field Time_Delay:Int
	Field Deadline_time:Int
	

End Type
Global Underwater_Effect:My_Underwater_Effect
Underwater_Effect = New My_Underwater_Effect



Sample_Image = LoadImage("your_image.png", MASKEDIMAGE)

Init_Underwater_Effect()

While Not AppTerminate()

	Current_time = MilliSecs()

DrawImage(Sample_Image, 0, 0, 0)

	If KeyHit(KEY_ESCAPE) Then End

Draw_Underwater_Effect()
	
		
	Flip - 1

Wend

Function Init_Underwater_Effect()
	Underwater_pixmap = GrabPixmap(23, 68, 352, 240)
	SetAlpha(1)

End Function
	

Function Draw_Underwater_Effect()
	

	
	Underwater_pixmap = GrabPixmap(23, 68, 352, 240)
	Underwater_image = LoadImage(Underwater_pixmap, MASKEDIMAGE)
	
	SetAlpha(1)
	
	If (Current_time >= Underwater_Effect.Deadline_time) Then
	Underwater_Effect.Time_Delay = 80
	Underwater_Effect.Deadline_time = Current_time + Underwater_Effect.Time_Delay
	
	
			
	amplitudeScaling = Rnd(1, 4)
	waveLengthScaling = Rnd(4, 8)
		
	EndIf

	For Water_x = 0 To 350 Step 2
	'DrawSubImageRect(Underwater_image, 423 + Water_x + amplitudeScaling * Sin(Water_x * waveLengthScaling), 69, 20 + amplitudeScaling * Sin(Water_x * waveLengthScaling), 240 + amplitudeScaling * Sin(waveLengthScaling), 1 + Water_x, 1, 20, 240, 1, 1, 0)
	DrawSubImageRect(Underwater_image, 423 + Water_x + amplitudeScaling * Sin(Water_x * waveLengthScaling), 69, 20 + amplitudeScaling * Sin(Water_x * waveLengthScaling), 240 + amplitudeScaling * Sin(waveLengthScaling), 0 + Water_x, 0, 20, 240, 0, 0, 0)
	Next
	
		
End Function



Derron(Posted 2015) [#29]
Maybe you should add some (very subtle) vertical movement too (like in waves).

Also think of reorganizing your code (too many globals):
Global Water_x:Int

could be replaced with

For local Water_x:int = 0 To 350 Step 2
Next


also I suggest to _not_ hardcode coordinates.

Another thing: You calc Sin(waveLengthScaling) 175 times per "Draw_underwater_effect()" - just do it once and store it in a local variable.


Underwater_pixmap = GrabPixmap(23, 68, 352, 240)
Underwater_image = LoadImage(Underwater_pixmap, MASKEDIMAGE)
->
underwater_image = LoadImage( GrabPixmap(23, 68, 352, 240) )


Global Underwater_Effect:My_Underwater_Effect
Underwater_Effect = New My_Underwater_Effect
->
Global Underwater_Effect:My_Underwater_Effect = New My_Underwater_Effect


BTW: if you already created a type for the effect, you could have a "Method Init()" and "Method Draw()" replacing the "draw_underwater_effect" etc.



"Optimizing" (re-layouting) your code will surely get rid of a bunch of your 120.000 LOCs.


bye
Ron


Takis76(Posted 2015) [#30]
What is the difference between:

Underwater_pixmap = GrabPixmap(23, 68, 352, 240)
Underwater_image = LoadImage(Underwater_pixmap, MASKEDIMAGE)


and

underwater_image = LoadImage( GrabPixmap(23, 68, 352, 240) )


The same with this too.

Global Underwater_Effect:My_Underwater_Effect
Underwater_Effect = New My_Underwater_Effect


And

Global Underwater_Effect:My_Underwater_Effect = New My_Underwater_Effect


Except of 2 lines of code less.


In my code I change the water_x variable and I made it as local.
And I added and water_y variable and I changed the code little , making the wave
waving and vertically too. Little better effect.

My code after the completion of the game it will be expected to be more than 500.000 lines. And after completion I will remove some duplicated lines about loading animation with lots of images which I have added them to image arrays.


Another thing: You calc Sin(waveLengthScaling) 175 times per "Draw_underwater_effect()" - just do it once and store it in a local variable.



Making the variable amplitudeScaling and waveLengthScaling local the program forgets the variables and the effect doesn't updates.

This increases the speed by 2 frames per second.

The new code which animate the wave horizontally and vertically too.

	For Water_y = 0 To 240
		For Water_x = 0 To 352
		DrawSubImageRect(Underwater_image, 423 + Water_x + amplitudeScaling * Sin(Water_x * waveLengthScaling), 68 + Water_y + amplitudeScaling * Sin(Water_y * waveLengthScaling), 20 + amplitudeScaling * Sin(Water_x * waveLengthScaling), 140, 1 + Water_x, 1 + Water_y, 20, 240, 1, 1, 0)
		Next
	Next


The only thing which will increase the speed is some fast grabscreen function.


Derron(Posted 2015) [#31]
@sin(wavelengthscaling)

It is a constant value from the POV of "within the for-next-loop"

So just have a

local variableName:Float = sin(wavelengthscaling)
For Water_y = 0 to 240
  DrawSubImageRect( ... , variableName, )
Next


compared to

For Water_y = 0 to 240
  DrawSubImageRect( ... , sin(wavelengthscaling), )
Next



@LoadImage( GrabPixmap() )

It save the need for another variable you are using. In the case of your code it even decreases usage of "globals" (which is always good).

@ bla:Effect = new Effect
Dunno if things get optimized or not - it just saves a line and there is (imho) no need to do this on 2 lines.

It is similar to writing:

local x:int
x = 10

compared to

local x:int = 10



Edit: just saw your for loop

You are drawing 240*352 single images _each_ frame !

I would go back to draw only 1*height-sized Sprites. You might scale the height of that sprites to enable a "waviness" look.

-> replace "water_y" with something depending on the water_x value and sinus ... so it "wavy" offsets the y-coordinate by -1 to 1 (or more, if you prefer a heavier wave).



bye
Ron


FBEpyon(Posted 2015) [#32]
I'm not sure if this is really going to speed things up...




Takis76(Posted 2015) [#33]
The above code above is very slow too 8 frames per second. :(

Is it possible with the first function above ccCopyImageRect when you pasting the image have the transparent color not present?

I will try to use ccCopyImageRect function. It does the copy fast.


FBEpyon(Posted 2015) [#34]
Yeah,

I have a power house computer, so things I do on it never translate very well to low end system.. Sorry


:EDIT:

Hey I was talking with my friend here at work about this and he is a EOTB expert.

He says that you should use Floor effects for reference to being under water.

He said to check out EOTB 2: DARK MOON (CASTLE DARK MOON) Floor effects.

Example would be just having bubbles floating to the top of the screen every few seconds, and blue halo around the screen (overlay).

Thanks,

FBEpyon


Takis76(Posted 2015) [#35]
I have played Eye of the Beholder 2 - The Legend of Darkmoon.
Eob2 Doesn't have any underwater level.
Eob3 had one.

What floor effects? Eob didn't have any special floor effect.
About bubble , I will add them when I will finish the grabbing problem. If I will not use the pixmap grab the game goes fast. In window mode I have 50 fps and in full screen I have 70 fps. In some more powerful computers I have 120 fps. But after grabbing everything goes very very slow.

I like my game to be played in older computers too.


Now I am working on Projectile Traps , Fireball and spell launchers.

I tested most of possible functions how to grab a part from the screen in realtime and all are slow then.

I will not add underwater effect for now in my game.


FBEpyon(Posted 2015) [#36]
Floor Effect : Spell effects that start from the bottom and rise to the top. Sorry that was the way it was explained to me.

And yes EOTB 2 did not have any underwater but used effects that would work well for making it look like someone was underwater being that the entire game was confined to one area.

I will still see what I can do to come up with something with shaders for you, but if I do that it won't be able to work with DirectX.


Takis76(Posted 2015) [#37]
How other programmers use shaders and work with Direct X?
I don't know nothing about shaders.
Why it will not able to run with DirectX? Even if I use open GL , Do I will need to change whole code?

I can make underwater effect elsewhere , but it will not be wavy like under water distortion.
Just adding a translucent cyan overlay doesn't do very realistic effect.
But the underwater distortion animation is much better.

About underwater bubbles and other stuff is fast. They are just sprites or particles.


FBEpyon(Posted 2015) [#38]
Direct X uses another shader (HSLS?) language than OpenGL, and I no nothing of the raw Direct X.

OpenGL uses GLSL for Shaders, which I'm able to program in. Because of that shader effects would be gone to anyone that wants to run the game in DirectX.

I would say for the distortion animation, you could look into doing random perlin noise overlay maybe, but wouldn't distort the game screen itself.

If you are trying to maintain the original feel of EOTB then I would say go with overlays, you could come up with some cool effects like a gradient teal overlay where its dark on the bottom, and lighter on the top for being under water.


Kryzon(Posted 2015) [#39]
OpenGL and Direct3D work differently with shaders, so you have to write the same shader twice, oncee in GLSL (the shader language used by OpenGL) and in HLSL as well (Direct3D).

Ideally you want to stay away from dealing with these APIs directly and want to do it through some game engine: most of them abstract the visual properties of a surface as a "material", which includes, among several visual settings, shader programs.

You're interested in getting the special effect in your game, not learning how the APIs work. Use a tool that suits your needs.


FBEpyon(Posted 2015) [#40]
Removed - Code did not work...


Takis76(Posted 2015) [#41]
What is your opinion?
If I will use GLGL does my game will work in other operating systems?
Do I need to change the graphic mode? (Now I am in directX mode)
Do I will need to change lot of code in my gem?

Where do I will find this GLGL module?
The copy of the screen is slow and I will use overlays but open GL would be nice.
Regardless I don't know how to program shaders. Or if I will find some ready made shader and load it.
But how do I will able to render a shader in Blitzmax?

:)


FBEpyon(Posted 2015) [#42]
I have been playing around with screen capturing and I was able to get screen capturing to work if you only loaded the screen once, and then loaded it again once you did some sort of action.

I can get about 60fps with my new code I finished last night, but once you put in the DrawImageRect then it drops to 13 to 15 fps. This seems to the what is limiting you from being able to use the grabscreen function I made (I have an improved version).

If you are just grabbing the screen once every time you move then it would be fine, but then monsters would need to be draw on as a overlay.

I will have to look through my shader module I made for Max2d, and see if it will help.


Takis76(Posted 2015) [#43]
Everytime players move in the dungeon , I must capture the new update.
But as you said , there are lots of animated things which needs to be updated underwater , like doors , traps , monsters , spells and other decorating stuff , so all of these things need to be updated constantly even if the players are idle or not move.
That's why I have so few fps. All of those things are behind the water effect.
Or in one word , after everything was drawn I capture the screen , but because things always changes , I keep recapture the screen again , regardless if the players are moving.

May I check your code? In my computer when I am drawing something with DrawImageRect I don't have so few frames. When I capture the frames reduces.

I need to give you a demo of my game to see what I say.


FBEpyon(Posted 2015) [#44]
If you were able to capture the frames once per move, and then if an enemy moves into frame then you would then recapture, so you would need a Boolean that says IsCaptured?, once this is done the capturing function is stopped, and you would just draw the new capture, and do what you need with the DrawImageRect.

This would work well I would hope..

I'm work right now, and would need to send you the new code, contact me through my email, if need be fbepyon (a) gmail.com ..

BTW : GrabPixmap is faster than GrabImage, and using PixmapPixelPtr(pix) you can modify the pixels pointers, also using PF_RGB888 as your format will maintain the MaskColor from my understanding which is how my new code is done.

BUT!!

I think I found your answer : http://www.blitzmax.com/Community/posts.php?topic=85478

Also any operation that requires this kind of processing would take up frame rates, but if you perform most of your operations once they are quick, but once you start repeating them in a loop it will slow things down a lot.

Make sure you keep your logics separated from your drawing operations as well this will help. That being said anything to do with Pixmaps are Logical Operations, and so they need to be done once, or limited..


Takis76(Posted 2015) [#45]
About capturing things not constantly, but after some action finish ,might will be a nice idea , I don't know might not work. I will need to add lots of code everywhere.
For example when doors are open, each frame, each door will need to capture the screen , or when some monster moves, will need to capture the screen , or when some spell will cast , for each frame of the spell animation or everything that animates it will need to call the capture screen function. I don't know if this fast things up or maybe will be exactly the same.

The only difference is , now I am capturing the portion of the screen immediately in fraction of milliseconds, but the animations (There are lots of them) have a small time interval between each frame and might will not slowdown the program because they are not so fast.

I will do some example when the player moves and slowly I will add capture option and to other actions. If the program will start to be slow I will remove it.

I saw the code in the link you gave.
The DrawImageArea() function draws over an image not on the screen directly.
So I will need to draw everything on an image buffer and then flip this image buffer to the screen.
I haven't tested this function yet , but I would like to ask , does this function paste the graphics with transparent color? Or do I will have the same problem with ccCopyImageRect() function example I found above in previously posts.

Even the ccCopyImageRect() function slow down the capture and it didn't support transparent colors too.

I will test the new code first and then I will try to make the trick with IsCaptured boolean , or add some variable to see if something is captured or capture immediately once after each action is over (For Example all animations).

Sometime I will send you an email to see how the game is looks like and how fast it is.


FBEpyon(Posted 2015) [#46]
You can still keep the color mask as long as you are maintaing the correct pixmap format when use loadimage.

Loadimage(convertpixmap(pixmap, pf_rgb888))

Let me know what you come up with.


TomToad(Posted 2015) [#47]
Here's something I tried. Using Viewport and setorigin, you can control what gets drawn where and create a nice effect.



TomToad(Posted 2015) [#48]
And a version which doesn't require ViewPort



Takis76(Posted 2015) [#49]
This effect is nice , but it doesn't look like underwater , more like tv jam effect.
Maybe if the waves are horizontal and vertical too.

Is not bad , but the problem now is not the effect. There are some code about objects and inheritance like Abstract and methods which I don't understand them much.


*(Posted 2015) [#50]
I would say study each area you don't understand in turn until you do, max is a good language which has load's of potential but can be more difficult than most due to poor documentation.


Takis76(Posted 2015) [#51]
You mean almost no documentation at all.
Everything I have learn was from some very few ebooks very very basic and with the help of people here.
There is no book or lessons which teaches Blitzmax in depth.


*(Posted 2015) [#52]
Yup its the one bugbear everyone had with Max there are a few sites dotted around with code snippets on them but not many unfortunately.


FBEpyon(Posted 2015) [#53]
I started writing a book on Blitzmax a while ago, but never finished it.

As far as not knowing Max very well, its a matter of breaking your code down into smaller projects, and learning how it works.

I ask for help a lot as well when I'm not sure how something works, but then I figure out most of it myself.

MiniB3d was good learning experience when trying to figure things out that I didn't understand about 3d, and now most of the things I do are hand written by myself from asking questions, and figuring things out by searching the forums.

If you have any questions you can always hit me up.

*EDIT*

Another useful things to have is a notebook, and write down what you are trying to do, and see if you can figure it out in paper before committing to code.

Thanks,

FBEpyon


Takis76(Posted 2015) [#54]
FBEpyon Did you receive my email?


FBEpyon(Posted 2015) [#55]
Yep I just replied to it.