PDA

View Full Version : nxPascal



User137
12-05-2011, 08:56 AM
I'm in process of renewing my game engine, started as Next3D here:
http://www.pascalgamedevelopment.com/showthread.php?5722-Next3D
Next3D was reserved name even though i don't think it was at 2007. Anyway nxPascal hit no search results.

nxPascal is a free game engine that tries to remain lightweight and portable. It is compilable under latest Lazarus on possibly all operating systems, and at least Delphi 7. So far this covers:
- 2D and 3D OpenGL graphics.
- Demos on most features, for both Lazarus and Delphi.
- 2D, 3D and much of gaming supporting math.
- Particle engine.
- Pathfinding with own rough but fast algorithm.
- Network class supporting TCP and UDP.
- Optional sound wrappers for OpenAL and BASS.
- Class for handling and rendering a user interface with buttons, listboxes etc.

Basically, they are all building blocks, separate units. You might choose to just want to use part of the features presented here, if you wish to use another graphics engine or something else. nxGL supports custom window creation, so you can do all that different way, but still being able to use even graphics features of this engine.

Project home: https://github.com/Zaflis/nxpascal

Old links:
code.google.com http://code.google.com/p/nxpascal/
Change log: http://code.google.com/p/nxpascal/source/list
Downloads: http://code.google.com/p/nxpascal/downloads/list
Wiki-help: http://code.google.com/p/nxpascal/wiki/Introduction

Carver413
12-05-2011, 12:07 PM
I was wondering what happened to your site and if you had decided to move on to something else. I was considering adapting your gui to a framework I've been working on for a while this would require some big changes do to the design I have in mind.

User137
12-05-2011, 11:11 PM
I suppose these are in good shape again :) I updated all the demos again, there is 5 for each lazarus and delphi.
nx_src.zip http://www.sendspace.com/file/p9odle
nx_demos.zip http://www.sendspace.com/file/rqualg

Texture demo should now look like this:
http://img862.imageshack.us/img862/4894/texturedemo.th.jpg (http://imageshack.us/photo/my-images/862/texturedemo.jpg/)
With most processes down i got that massive 13000 fps with lazarus compiled version. Delphi got to "over 9000" too, lol.

So i got the render settings wrapped up with new features SubBlend that can be used for very cool dark flames, and front/back face culling (visibility). New 5th demo is about custom window creation, and basically how you can integrate nxPascal with other graphics libs. That is handled by new compiler directive in nxGL.pas

Carver413
16-05-2011, 01:07 AM
Thanks for sharing, I had a little trouble getting the demos to work. first the version of dglOpenGL you are using would not compile with lazarus/linux. I downloaded the newest version and that fixed that problem. second problem required me to add ReadOpenGLCore to the CreateGlWindow code. I only got about 60 - 120 fps guess my gfx card is too wimpy. I think that more demo's would be quite helpful in getting others to make use of your work.

farcodev
28-05-2011, 04:53 AM
Have you a compiled demos archive too ?

User137
26-06-2011, 08:44 PM
Have you a compiled demos archive too ?
Demos are still working (and i wish to add more of them in the future), but i don't include compiled executables in packages. Would you have an idea for additional demo?

Finally got myself coding again, and the result is new nxSound.pas
It is using Noeska OpenAL header, for which i'm not sure how to give proper credit to... It is compiling and running fine with Lazarus and Delphi, like other units.

It is simplified OOP approach, and its autocreating/destroying itself by just adding nxSound in uses list. Like OpenAL, this supports multiple buffers and sources with 3D positional sound. Buffers and sources are separately stored, essentially letting multiple sources use same buffer, the sound file.

This is a simple example that plays ding sound:

procedure TForm1.FormCreate(Sender: TObject);
begin
sound.AddSource('ding', sound.AddWAV('ding.wav'));
if nxError<>'' then showmessage(nxError);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
sound.source[0].Play;
end;

In other news GL UI is able to drag its windows with mouse...

I'll update the engine packages and download links if there is interest to.

User137
05-08-2011, 06:52 PM
Added all file links again, this time i also added compiled demos, they include media files needed to run them. Both Lazarus and Delphi versions for source code.

Latest addition is framebuffer class of which 1 demo is about. A rotating cube which faces are showing the same screen of rotating cube which faces contain rotating cubes and... lol

What else.. hmm i forgot to make a demo about nxSound, but you can see brief example in above message, it is at that simple level.

The future:
- Researching more on OBJ file format i discovered that it not only supports triangles but loading must also be able to use polygons. This was a setback to my 3D model code which i have to reorganize fundamentally. Something along the lines of TPolyModel and TTriModel would be still for triangles only. For gaming use, vertexarrays etc all must be triangles. Internal code will convert polygon models into triangle models and use normal generation where needed.
(Knowing that i updated my old 3D editor for being able to load all OBJ models now, just nxEngine itself can't yet.)
- UIEditor: I still have plans to make the component editing more like designing forms is in Delphi. Meaning you could select many items, drag them or change multiple properties at the time. I'm also not pleased with the layout.
(- Possibly article of making simple program or game... make you know more about the engine :) )

edit: I still don't know how i'd add musics. Looked into OpenAL playing but didn't get anything working. Tips?

Rodrigo Robles
26-08-2011, 10:46 PM
edit: I still don't know how i'd add musics. Looked into OpenAL playing but didn't get anything working. Tips?

OpenAL was designed to work with raw sound files like WAV. It doesn't have support for music files like MP3 or OGG. We should code the player... Fortunately Ivo Steinmann did this work for us. The project Mundo (http://sourceforge.net/projects/gamemundo/) uses it. There is two units, ogg.pas and vorbis.pas, you can find it at http://gamemundo.svn.sourceforge.net/viewvc/gamemundo/trunk/src/client/

cst_zf
20-09-2011, 06:54 PM
Can you tell me how to show fade-in and fade-out effect with nxPascal?

User137
23-09-2011, 03:59 PM
I just got a weird theory to optimize texture memory... There are times when you just need textures that are not power of 2, for example odd 300x200 image. nxPascal can currently load that as either scaled to nearby size (256x256 in this case) or pixel-perfectly unaltered but fit in 512x256 "frame". However the "frame" will in this case waste alot of unused memory.

What i came up with (as just idea so far), is that i'd have 2 integer (word) variables per texture: XPart, YPart. The loader would calculate perfect fit for image that is divided in 1, 2 or 4 subtextures. That 300x200 would be divided in 2 parts to make as whole a 320x256 "frame", because the height cannot be split in 2:
256x256, 64x256

If i count memory saving for RGBA image:
300x200 originally as 512x256 "frame" needs 524288 bytes.
2 subtextures need 262144 + 65536 = 327680 bytes
which is 62.5% of memory that would normally be reserved.

Obviously this will need draw functions to adapt to subtextures but it shouldn't be problem. 3D model surface would be unable to use this well, but models should always use the scaling option anyway for repeatability.
Edit: Actually it is big problem if want to support patterned drawing... I'd propably disable/ignore patterns when this is used.

Also, i just got BASS musics working with Lazarus so that's what i'll be using. Need to make a class wrapper to it to ease the procedural DLL header unit.

code_glitch
24-09-2011, 01:08 PM
Hay all nxPascal contributors, a new post slipped the mod net while I was away... See above.


Can you tell me how to show fade-in and fade-out effect with nxPascal?

Cheers.

User137
24-09-2011, 03:19 PM
What is mod net?

For the problem there is many ways, but by fading you propably mean fading whole screen to black and back in to new screen.

In 2D mode you can accurately draw a faded black rectangle on top of other graphics, or you can use black glClearColor (is default) and change alpha color of all your graphics. Also to draw rect in solid color you need to disable texture.

tex.Disable;
nx.Enable2D;
nx.SetColor(0,0,0,fade);
nx.RectT(0,0,nx.Width,nx.Height);
nx.Disable2D;
tex.Enable;

code_glitch
24-09-2011, 06:13 PM
What is mod net?

Simply the net in which I catch spam and other nasties and approve posts from new users. Its the reason why you see a nice clean PGD that's viagra add free and clutter free from spam :) - there can be anywhere from 5-50 posts to delete per day.

cst_zf
25-09-2011, 09:40 AM
What is mod net?

For the problem there is many ways, but by fading you propably mean fading whole screen to black and back in to new screen.

In 2D mode you can accurately draw a faded black rectangle on top of other graphics, or you can use black glClearColor (is default) and change alpha color of all your graphics. Also to draw rect in solid color you need to disable texture.

tex.Disable;
nx.Enable2D;
nx.SetColor(0,0,0,fade);
nx.RectT(0,0,nx.Width,nx.Height);
nx.Disable2D;
tex.Enable;

I means fading-out rendering a graphics with alpha value from 1.0 to 0.0 gradually and fading-in from 0.0 to 1.0.
That is a useful effect in some situations.

in this question, i need a procedure like DrawAlpha(left, top, width, height, alphavalue)

cst_zf
25-09-2011, 10:33 AM
FrameBuffer in src_demos/delphi_demos reports an AV exception.

User137
13-10-2011, 07:56 AM
FrameBuffer in src_demos/delphi_demos reports an AV exception.
Sorry i can't reproduce the AV with Delphi 7. However nxGL is not catching OpenGL errors for unsupported video cards/drivers at the moment.

New addition to nxPascal and updated source download link. This is what i mentioned earlier, what i now call TQuadTexture. By adding nxGLExtra in uses-list lets you use memory optimized textures with rotation and scaling. TQuadTexture uses TGLTextureSet for holding 1-4 textures that are fitted for odd and any texture size, like 260x550 would define 4 power of 2 textures and use memory of 260x576 pixels (256+4 x 512+64).

Normally using GL_NEAREST has no issues with scaling, but with linear filtering there is TDX-feature in use by default that makes visible line-errors between textures disappear.

To use, simply have variable qt: TQuadTexture; somewhere, and

qt:=TQuadTexture.Create('test.png', true); // Loads with transparency on
..
nx.SetColor(1,1,1); // Use white color
qt.Draw(0, 0); // Simple draw in point (0,0). Textures are set automatically.

User137
15-10-2011, 06:06 PM
Decided to make another video. Combination of various features, first off background is 800x600 QuadTexture. Followed by 2 particle launchers at bottom corner, from which right side is a clone of left one. Mouse cursor drops snowflakes which have gravity applied to them. Then there are 3 trail effects also part of particle engine.

Top top it off, all of that is drawn only in framebuffer. There is a 50x50 grid of indexed GL_QUADS vertexarray, which acts as screen. This let me do a "collapse" effect at where blue trail is moving, basically the grid bends towards it like spacetime :D

Background music comes also from the application, by nxBass unit, that is some of BASS library simplified to OOP way of programming.
This is all there is to it in main program, and it can handle alot of formats:

bassSound:=TBassEngine.Create(handle);
if not bassSound.CheckErrors then begin
bassSound.Add('music','data'+PathChar+'test.s3m'). Play;
end;

http://www.youtube.com/watch?v=oa7vw20rcE8

Wireframe option is added to render settings. Unfortunately i can't upload engine sources yet because this broke my model demo that used placeholder particletype. 3D particle rendering isn't ready yet. But adding me to MSN or asking with private message always works and i can send anything.

Compiled demo added to attachments, let me know if there are any problems running it :)

chronozphere
16-10-2011, 04:51 PM
Works flawless here. > 120 FPS on my 8600GT. Good job on this one. ;)

User137
16-10-2011, 05:22 PM
That seems hard-limited maybe, vsync? Mine is not forced on in driver settings. It actually has no FPS limiter, not even sleep(1), so its giving me 1500-2200 FPS.
Forgot to mention, the grid is toggled with spacebar key.

Also i will include this demo in the nxPascal demos sometime soon, need convert the Delphi version aswell.

chronozphere
16-10-2011, 07:26 PM
Seems very likely that my drivers use v-sync then. It's pretty stable around 120 FPS. :)

User137
17-10-2011, 04:20 AM
Finally got done what i was supposed to. 3D support for particle engine is there, and you can test it all. Check first post for updated links. Mainly do check the model and effects1 demos, they're quite an update to earlier ones. All demos are tested working on Lazarus and Delphi7.

User137
06-11-2011, 07:26 PM
Spent pretty much whole day fighting with Synapse network library ::) I wanted to test it in action so i had to make a small "game". In the process alot of bugs got found and eliminated, and finally everything worked smooth. My test had 5 client windows connected to the same server, each with unique 2D spaceship that was showing flying on all screens. Random crashes at exit are no more.

What got me puzzled for long time was simple string comparison. In the authentication i have string1 and string2. Then string2:=string1; Now pass string1 into MaskCrypt() and i discovered that string2 changed aswell :o Crazy pointer logics there. So in order to copy string to another i have to do it with string2:=copy(string1, 1, 255);

User137
03-01-2012, 05:38 AM
New version released again, and cleaned up first post a little. I finally got the 3D model class in shape that it can be published, and i'm really happy with its potential now. Once for example OBJ is loaded in it, i can use its simple commands to convert it to W3D format, or back and forth between triangle and polygonal model classes. So polygon class supports triangulation, while both classes are able to recalculate normals based on face groups.

Some thought process also went into textures regarding models, which are now automatically freed. For example if i have 3 models that use 1 same texture, when i load them in, only 1 instance of that texture is loaded but they all use it. But only after all 3 of them are freed, then the texture is freed too.

http://www.pascalgamedevelopment.com/attachment.php?attachmentid=687&d=1325566832

What's next: I'm looking a bit into normal (bump) mapping with GL_ARB_multitexture, but its just not working yet. I just really have to get that done some point. Also there is a minor glitch on some test models regarding W3D and OBJ... They work in majority of cases and i fixed all crashable bugs, but there seem to be something that i miss in the W3D->PolyModel conversion because 2 of the test models shows texturemap wrong for 1 vertex. At some point i might consider 3DS format addition. Also, do not think that W3D as it is, is final model format i'll use, it is not. Just being the only format i have modelling tool for.

Another i'd like to put in is a 3D physics engine and bone animation. Have not looked into those at all yet, although there is already some bone support in the model classes.

paul_nicholls
03-01-2012, 08:48 AM
Lookin' great!

paul_nicholls
03-01-2012, 11:00 AM
Decided to make another video. Combination of various features, first off background is 800x600 QuadTexture. Followed by 2 particle launchers at bottom corner, from which right side is a clone of left one. Mouse cursor drops snowflakes which have gravity applied to them. Then there are 3 trail effects also part of particle engine.

Top top it off, all of that is drawn only in framebuffer. There is a 50x50 grid of indexed GL_QUADS vertexarray, which acts as screen. This let me do a "collapse" effect at where blue trail is moving, basically the grid bends towards it like spacetime :D

Background music comes also from the application, by nxBass unit, that is some of BASS library simplified to OOP way of programming.
This is all there is to it in main program, and it can handle alot of formats:

bassSound:=TBassEngine.Create(handle);
if not bassSound.CheckErrors then begin
bassSound.Add('music','data'+PathChar+'test.s3m'). Play;
end;

http://www.youtube.com/watch?v=oa7vw20rcE8

Wireframe option is added to render settings. Unfortunately i can't upload engine sources yet because this broke my model demo that used placeholder particletype. 3D particle rendering isn't ready yet. But adding me to MSN or asking with private message always works and i can send anything.

Compiled demo added to attachments, let me know if there are any problems running it :)

If I may ask, what is the music in the above video?
I quite like it :)

User137
03-01-2012, 04:49 PM
If I may ask, what is the music in the above video?
I quite like it :)
I think it's S3M called "In the mist", was free download from some site. It's actually the demo (this demo is included in the downloads) playing it with BASS library :) I didn't separately attach it to video.

Oh, i could also make a small game for a demo too. Anyone have ideas what it could be? I'm actually fan of Tetris myself, lol.

paul_nicholls
03-01-2012, 09:52 PM
I think it's S3M called "In the mist", was free download from some site. It's actually the demo (this demo is included in the downloads) playing it with BASS library :) I didn't separately attach it to video.

Oh, i could also make a small game for a demo too. Anyone have ideas what it could be? I'm actually fan of Tetris myself, lol.

Thanks for the song info, I found and downloaded it :)
http://lite.modarchive.org/index.php?request=view_by_moduleid&query=71153

Hmm...maybe I should see if I can make some code to play S3M songs - those type of songs are very small in size and would be perfect for inclusion into my game, but I don't want to distribute YAL (Yet Another Library) haha

Not sure what type of game you could make, maybe a 2d tile-based plaformer that has 3d objects in it? That could be fun and not too hard :)

SilverWarior
04-01-2012, 12:32 AM
If you want smal sized songs you might rather use MO3 format, wich is also supportet by BASS sound library. MO3 format is actualy a lot like MOD format, except that all the samples are being compressed by mp3 compression, while MOD format uses samples in plain WAV format.

But if you realy intend to make your own way off playing songs I have an interesting idea. I was planing to do this myself but my knowledge on this area is too low.
What I was thinking is that instead of having samples stored in each song you have one master collection of samples and songs itself are just a set of instructions of when each sample must be played. This will lower the space required for theese songs especialy if they use same samples. Also since you will have all the samples loaded into memory at the same time you could easily make posible of mixing two or more songs together at any time.

WILL
12-01-2012, 11:03 PM
I like your demo. It's very demoscenish. ;)

Are you making much progress on your game which was using this engine as well?

User137
13-01-2012, 02:32 AM
I haven't decided yet. In the end a platformer would take quite some work, in the graphics, and overall. I could make it an endless shooting game which would in time get harder and harder, and then just compete of high score. I have thought of a way to randomly spawn enemies and their "retro look" movement patterns, so i wouldn't need a level editor at all. Maybe you could even upgrade the ship while flying it... Because i dislike the way retro games get their weapon upgrades by directly assigning them from looting. It may override a good weapon you were used to with something bad, so i'd rather use a "ship builder" dialog you can open at any time.

paul_nicholls
13-01-2012, 03:27 AM
OT:

If you want smal sized songs you might rather use MO3 format, wich is also supportet by BASS sound library. MO3 format is actualy a lot like MOD format, except that all the samples are being compressed by mp3 compression, while MOD format uses samples in plain WAV format.

But if you realy intend to make your own way off playing songs I have an interesting idea. I was planing to do this myself but my knowledge on this area is too low.
What I was thinking is that instead of having samples stored in each song you have one master collection of samples and songs itself are just a set of instructions of when each sample must be played. This will lower the space required for theese songs especialy if they use same samples. Also since you will have all the samples loaded into memory at the same time you could easily make posible of mixing two or more songs together at any time.

Just so you know, I was allowed to use BeRo's XM player code in my game which can play .mod and .xm tracker files, so my game's exe has shrunk down from over 14MB to around 3MB! This is with increasing the music track count from 1 to 8!! :D (Thanks BeRo!)

User137
13-01-2012, 05:00 PM
Have to be fairly pleased after few hours of fun with this project (yes, i started from scratch today). This is how it looks so far:

http://i44.tinypic.com/vrg5tk.png

It is taking under 20% of cpu at locked 100 fps rate for me. Curious to see later if different setups slow it down or not.

chronozphere
13-01-2012, 08:36 PM
Ah pretty good! You need a bunch of stars in the background though... and some explosions! ;)

User137
14-01-2012, 01:39 AM
Damn, i've already found 2 bugs from the engine because of this game ??? Not only models had no textures at first, because Displaylist class didn't take into account texture references (so they were auto-freed when model was destroyed), but also simple FPS counter had a bug... At least they're fixed now.

paul_nicholls
14-01-2012, 02:39 AM
Damn, i've already found 2 bugs from the engine because of this game ??? Not only models had no textures at first, because Displaylist class didn't take into account texture references (so they were auto-freed when model was destroyed), but also simple FPS counter had a bug... At least they're fixed now.

hehe, isn't that what games are for...to test their game engine? :D

I have found bugs in my engine when making The Probe using it, was rather helpful! ;)

Good luck!

cheers,
Paul

User137
22-01-2012, 03:34 PM
School and playing other games are pressing on a bit so time is limited, but project continues, here's little more progress info and screenshot 8) New thing there is rotating turret objects. This screenshot is first scetch about the upgrade mode, which also shows at the beginning for that controls hint. At any point of game you can press Enter (or Space) to enter this upgrade mode, where you can change primary and secondary weapon and balance ships resources between shields, weapons and energy generation. There will be collectable upgrades to which increases the resources, and available weapons.

Also i finally got the framerate issues solved, so it really is smooth 60 fps even on schools silly computers. I've been very reluctant to do the basic things like explosions and bullet hits, simply because i want to do the hard work on weapon systems classes first... Once they're done, things will start to get showy really fast :P Like there is already some definitions for beams and homing missiles even though they're not showing yet.

I like customization, simplest pulse cannon might stretch to various styles like: switching turret, simultaneous dual fire, volley, rapid fire, way faster but more random and less damage per pulse. Etc... You might have pulse cannon on both fire1 and fire2 buttons but customize them in different way.

http://imageshack.us/photo/my-images/803/screenshot1uq.jpg/

User137
25-01-2012, 09:48 PM
Can't resist filming it in action 8) Yus, it has musics and sounds. Although sounds start clicking after a while and i have not solved that problem yet. Laser weapon is not yet in showcase shape, besides with primary and secondary weapon i was only able to show 2 kinds of weapons. The zoom-in mode only serves as key guide for now, until i get to design the upgrade info in it.


http://www.youtube.com/watch?v=CoXJbSZddOA

WILL
30-01-2012, 12:44 AM
Very cool demo. When are you planning on creating a website to host documentation and the game engine and the demos it's self?

paul_nicholls
30-01-2012, 02:27 AM
Very cool!! I would be interested to see how it runs on my laptop! LOL

User137
24-02-2012, 07:28 PM
Little update again. I uploaded latest version of nx_src.zip, engine source code. Some recent Lazarus of FPC SVN versions broke latin characters. That is fixed now, in addition to other minor fixes in past months i have forgotten... nxBass wrapper is fixed about wav-sample channel counts, so that the "clicking" bug in the game demo is fixed. Also, beam weapons for both turrets are done in the demo now. It's all about adding more content, as if i could do that while playing Star Trek Online :D

pitfiend
26-02-2012, 10:06 PM
Hi user137, I tried your stuff on Delphi 2007, it seems to work fine, just some fixes here and there (basicly because you use tpngobject and I have tpngimage, they are the same). The only demo that didn't compile, was the one that uses bass, something about a property channel that was not declared or something else. Didn't have enough time to trace the error' source or to fix it.

User137
27-02-2012, 03:09 PM
Seems that i didn't try all the samples :) I can see compile errors in Effects1 demo. Quick fixes:
- Change bass.channel[] references to bass.sound[]. This relates to recent change in BASS class to use more descriptive names, and sound that actually uses real channels inside it. Not all sounds use more than 1 channel, ie. streams.
then in nxGLExtra, in class TParticleEngine, change to:

procedure Move2D(mps: single=1);
procedure Move3D(mps: single=1);
mps stands for MovementPerSecond, but actually i will change it to MovementPerTick what it actually means. If default scale is 1 it will move at speeds at which are given to it. But with this parameter you can control how much particles move if fps changes, so that actual speed remains same in all occasions.

Updated demos and source downloads.

User137
28-02-2012, 04:24 PM
Just started a project for this in http://code.google.com/p/nxpascal/

But i'm completely new to that site, so i'd accept some help to set it up :) SVN at least. Send me a private message if interested to chat or be admin. MSN and Steam are on daily basis.

Edit: Nvm, SVN is set up and available.

Relfos
29-02-2012, 11:30 AM
I just got a weird theory to optimize texture memory... There are times when you just need textures that are not power of 2, for example odd 300x200 image. nxPascal can currently load that as either scaled to nearby size (256x256 in this case) or pixel-perfectly unaltered but fit in 512x256 "frame". However the "frame" will in this case waste alot of unused memory.

There's no need to rescale or pad textures, most graphic cards support non power of two textures, also try adding support for DXT compressed textured formats, that will give you a slight boost in performance :)

User137
29-02-2012, 01:24 PM
Last time i tried some big texture with non power of 2 it came out white. I suppose you mean reduction in memory use? :) Compressed image goes through algorithm when rendering, so raw texture data will always outperform it. But it's a good idea for some situations, i haven't heard of this concept before, or how to do it with OpenGL.

Also, making 4 textures out of non-power of 2 texture is not the default way in nxPascal. It is a separate feature through TQuadTexture class. It is shown in the Effects1 demo.

Relfos
29-02-2012, 01:58 PM
Compressed image goes through algorithm when rendering, so raw texture data will always outperform it. But it's a good idea for some situations, i haven't heard of this concept before, or how to do it with OpenGL.
Not exactly, as the decoding is built-in into the hardware, and as they take way less space on memory, it usually rans faster (but might look worse visually).
About the texture looking white, maybe your card does not support it?
Here's a link about it:
http://www.opengl.org/wiki/NPOT_Texture

User137
05-05-2012, 02:09 PM
Oh yes, i had alot experience with compressed textures after last comment, with Skyrim. Indeed they look a little worse.

nxPascal is now at SVN revision 15. Just today went through all the demos again that they work, and updated paths more conveniently. They should now work directly, with no modifications to project settings.

Then, noticed the network demo crashes on exit, with Lazarus. I'm still using the old version of synapse though. Will check that when i get time. (Could be that i modified my own version of synapse when searching for its memory leak. There is one.)

Licence is also changed, thanks to cocce here. MIT license should finally allow to use nxPascal's full source code with commercial and non-commercial projects with almost no limitations.
http://www.opensource.org/licenses/mit-license.php

Ah, almost forgot... Tools folder is opened too. UIEditor, UITester and edit3d-modelling software are in the SVN trunk. Edit3D conversion project for Lazarus started now, but there is zipped the old Delphi version with its source. It will not be 100% identical though, i have hopefully learned the past versions mistakes, or design inconsistencies...

User137
02-08-2012, 03:55 PM
Updated .zip files in the code.google site. SVN trunk gets updated more often though.

New:
- nxGame unit got a big kick-start. New "demo" is added called GameTemplate. This is a base of a game that use new game class, in compact and object oriented way. It handles framerate, input (keyboard and mouse), and modding folders. Basically you inherit your game from TGameHandler class, and override its GameLoop and Draw procedures. Even further, i'm inheriting it twice in the GameTemplate, to more clearly distinct graphics in its own unit, and game events in other.

And for modding, you can have multiple different mod-sets in your program folder. Using game.modPath to set, and game.GetPath() you can ask the system which path you need for each texture/sound/data-file etc. If mod-folder doesn't have certain file, then original is used.

User137
10-08-2012, 04:05 PM
Wow, this site seems quiet :p Thought to let you know of a new unit i added, nxData.pas. TDataStore class is made for keeping large chunks of data loaded in memory. It uses compression to units that are not used for (by default) 15 seconds. Tested in my game on FPC but also compiles with Delphi, using zlib (or fpc zstream). Multithreading was added just today too, so that it shouldn't interfere with rendering thread, if renderer simply hints it that it wants certain chunk loaded, it can render it when thread has finished loading it.

I don't know of any issues with it at this point, at least works with 2D game, and because it's internally 1-dimensional, it doesn't care what sort of project it is used for. Minecraft-like 3D-chunks, or just as simple database? Why not! Saving my game world on disk, 45Mb millions of tiles data was shrunk under 2Mb. It is similar to what it is like loaded ingame.

paul_nicholls
10-08-2012, 10:53 PM
Sounds like a useful unit! :)

User137
17-08-2012, 10:29 PM
Just quick sidenote, that GLSL fragment-shader is now supported. Fpc and Delphi demos about the topic included. Code about it in main program, is like most other stuff in nxPascal, short and simple!

It is not long class as you can see there http://code.google.com/p/nxpascal/source/browse/trunk/src/nxGL.pas
but if i plan to make a default shader for 2D, and simulate glVertex, glColor etc with VBO, it may grow in size. For now i only have some theory in mind on polygon-stack... Every Draw, DrawRotate commands etc. are at the moment using old glBegin- style. 3D-models use vertex-arrays, and VBO is so far unsupported (unless you do it yourself with dglOpenGL header).

Demo is modified and simplified of earlier:
http://www.pascalgamedevelopment.com/attachment.php?attachmentid=894&d=1342559367

Also updated compiled win32 demos link, so you can preview the latest:
http://nxpascal.googlecode.com/files/nx_compiled_demos_2.zip


Last time i tried some big texture with non power of 2 it came out white.
Forgot to update on this topic too... There was parameter error in glTexImage2D. InternalFormat cannot be 3 or 4, but instead GL_RGB and GL_RGBA. After this small fix, texturing unit is now supporting non-power of 2 sizes for images as default. Say hello to your 800x600 backgrounds ;)

User137
23-08-2012, 05:23 PM
nxPascal actually has SVN changelog too: http://code.google.com/p/nxpascal/source/list
though i can tell more about the changes here when simple log-entry is not enough.

I was requested few new features for the engine and so here is some new stuff:

CreateCube, CreateSphere, CreatePlane, CreateTorus procedures are added for 3D-model class.

Also there is new demo on mouse-picking. It features flying in free 3D-space, and pointing objects with cursor. It is supporting object positioning and rotation with matrix. Both only available in SVN for now.

And managed to create default shaders for 3D and 2D supporting colors and textures. So some point the VBO renderer will progress again, and i am finally rid of all glBegin etc calls. (They are only used in 2D.)

hwnd
23-08-2012, 08:14 PM
So this means, most of the stuff will be based on shaders?
I guess i have to learn them finally. Atm i don't know nothing much about them, they are still some black box to me that does some magic. But how, no idea.
Maybe i just lack interest in shaders. Particulary because i have old PC with old gfx card: Ati Radeon 9550.


My suggestion to you. If you make any new test, like this shader example, also you said something about torus test.
You should include them as examples / demos. Because there is no help file, examples / demos is the only reference.
If someone just doesn't post questions here or PM for getting help. But still, i think, every bit of demos helps.


EDIT EDIT EDIT:
I think i found a bug or it's just my Delphi.

Anyway, in file nxGL.pas at lines 87 and 88, there is missing 'overload' directive.

It looks like this by default:

procedure Render(Indexed: boolean = true);
procedure Render(first, _count: integer; Indexed: boolean = true);

But should be:

procedure Render(Indexed: boolean = true); overload;
procedure Render(first, _count: integer; Indexed: boolean = true); overload;

If there is no overload directive, Delphi throws an error. I just downloaded latest from svn, tried to rebuild all and got an error.

User137
24-08-2012, 10:25 AM
So this means, most of the stuff will be based on shaders?
I guess i have to learn them finally. Atm i don't know nothing much about them, they are still some black box to me that does some magic. But how, no idea.
Maybe i just lack interest in shaders. Particulary because i have old PC with old gfx card: Ati Radeon 9550.
Hmm, my card is Radeon 5700. Unsure which is newer. All you need is OpenGL 2.0 support to use pixel-shaders, and current versions are already going at 4.0+. So all card i know of propably supports them. Also, if shaders would make rendering slower, there wouldn't be point in using them right? :P I believe it will be opposite, and great boost to performance actually. You can check the current shader-candidates in nxShaders.pas. I use its 3D version in the bump-mapping demo. (change 1 parameter and it disables normalmap)

Also about the rendered i mentioned, it is for 2D. All 3D-graphics are already using vertexarrays, and can be easily adapted to VBO, because the data buffers remain the same. But all DelphiX-like commands like DrawRotate needed the new 2D-shader built. I can do all the array work behind the scenes, so a new just starting out game programmer might not even know that stuff is drawn with pixel-shaders.


My suggestion to you. If you make any new test, like this shader example, also you said something about torus test.
You should include them as examples / demos. Because there is no help file, examples / demos is the only reference.
If someone just doesn't post questions here or PM for getting help. But still, i think, every bit of demos helps.
It is good idea. Redownload the SVN, you'll see Picking demo now use all the new models, except Plane, because why show just 1 rectangle?

Some point i may try land generation with the plane, using it for heightmap. But static model is rarely good idea for land, especially if it can be big. But it can act as a dynamic buffer either way. Also if you Assign it to TVertexArray you can add colors-array per-vertex.

Yeah same code didn't compile on my Delphi either. It's always 1 change in fpc that can make things break for Delphi :D But it's fixed.

edit: Seems like first post wasn't up-to-date with links :o

User137
31-08-2012, 03:50 PM
There was big math update yesterday for quaternions, and operator overloading support for fpc for vectors, matrices and quaternions. But today something more interesting that is 3D-sounds with BASS. The sound class would let me if i wanted to: change track position on each sound source, change their volumes, change how fast the sound fades out and so on. Even doppler effect is present when moving fast beside sound sources.

http://www.youtube.com/watch?v=IKoE-JL7OXg

hwnd
31-08-2012, 03:58 PM
is this as new demo included? or combined with picking demo. all in one?

examples will be hard to follow, if so

User137
31-08-2012, 04:54 PM
It isn't currently included in any demo. Also the functions used are quite straightforward, even default values are tuned so that they would fit most purposes with no configuration.


sound:=TBassEngine.Create(handle, true); // Set true to enable 3D

// Move and rotate listener while sounds are playing
sound.listener.SetLocation(pl.position);
// Front and up vectors from listener's rotation matrix
sound.listener.SetOrientation(getvector(pl.rotatio n, 2), getvector(pl.rotation, 1));

// Attach sounds to objects
for i:=0 to high(obj) do begin
sound.Add('music', 'sounds\test.s3m', true); // Again true to enable 3D for this specific sound too
with sound.sound[i] do begin
// Move and rotate object sounds
SetLocation(obj[i].position);
SetOrientation(getvector(obj[i].rotation, 2)); // front vector "where object is looking at"
looped:=true;
Set3DAttributes(0, 100, 360, 360, 0); // Detailed config values, optional
Play;
end;
end;

User137
05-09-2012, 06:41 PM
Added a ton more information to wiki today: http://code.google.com/p/nxpascal/wiki/Introduction
Hope you can find it useful, but remember to let me know of areas that desperately need more information. Many unit-descriptions are still just scratching the surface, but i felt like that was alot of work done.

hwnd
05-09-2012, 09:35 PM
Looks nice so far. Such wiki is very welcome.

btw i wanted to ask. do you know any path finding lib or code that works in 3D?
i mean that works with XYZ. i would like to do some tests. if one mesh can follow or find a path to second, if its upstairs or something.
or the pathfinding method doesnt matter for such a thing.
and nxpascal pathfinding is enough?
i have some ideas here.

User137
06-09-2012, 04:55 AM
It's currently not set to work with 3D. It is a tile-based finder where adding 1 dimension would explode its memory and performance needs. Most optimal thing would be to build a tree of nodes for the map. It would work for 2D and 3D, work faster and take less memory than current, but it building such tree is not simple. Especially when there's alot of different kinds of game worlds. Personally i haven't had need for pathing for long time so it's just 1 of those things left aside ;)

SilverWarior
06-09-2012, 05:36 AM
For 3D pathfinding I would recomend using A* pathfinding algorithm or even Near Optimal Hierarchical Patfinding (HPA*) http://aigamedev.com/open/review/near-optimal-hierarchical-pathfinding/

If you decide to use A* pathfinding there was news post from Will regarding example for using A* pathfinding algorithm http://www.pascalgamedevelopment.com/content.php?312-Chris-Shows-Us-How-A*-Is-Done
While the example shows A* pathfinding algorithm on 2D surface it can be easily converted to be used in 3D world becouse it bases on node system.

As for HPA* I haven't found any examples writen in pascal jet and that is a shame becouse HPA* is much more optimized and uses lots less memory than plain A*.

LP
06-09-2012, 01:39 PM
For 3D pathfinding I would recomend using A* pathfinding algorithm or even Near Optimal Hierarchical Patfinding (HPA*) http://aigamedev.com/open/review/near-optimal-hierarchical-pathfinding/
A* path-finding (http://en.wikipedia.org/wiki/A*) is a special case of Search Algorithms (http://en.wikipedia.org/wiki/Search_algorithms), specifically Dijkstra's algorithm (http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm). There are many more such algorithms and each can be better or worse depending on the given situation.

code_glitch
06-09-2012, 06:16 PM
Personally this is what I do - although I've never thought of the problem in a 3d plane to be honest, this is what I found to be my 'simplest' efficient self hauled design, which turns out to be a little like an A* search pattern... I'll write it in pseudo-code to make it shorter and easier to understand :)



The records I use are as follows:
A 'path' which contains -
A boolean array the same size as that of the area to navigate but empty at the start.
The final number of 'steps'/waypoints used to reach the destination
Array of X,Y cooridnates of each waypoint
An array of bits the same size as the area to navigate. 0/False signify space that can be moved into, 1/True designate an obstruction.
Another array of bits the same size as the area to navigate.


Thus the algorithm goes:


proc algorithm.run()
1. Input sensor data into the area grid (ie. Flip the bits so that the array now contains the obstructions.
2. Determine how many options the algorithm should consider - dependant on avilable memory/cpu time. Call this integer MaxRoutes
3. while c < MaxRoutes do //where c is the current route being processed
3.0 c += 1 //forgot to add at first, so thats why its 3.0 XD
3.1 AddNewRouteToArrayOfRouteOptions() //Adds a new, empty route data type to the array
3.2 NewRoute.Process() //see below
4. while c > 0 do
4.0 c -= 1
4.1 ArrayOfRouteOptions[c].Optimize(OptimizeLevel) // see below
5. ShortestRoute := GetShortestRoute() //a simple loop that checks all the considered options' lengths and finds the shortest
6. FollowRoute(ShortestRoute)
7. CleanMemory()
end;

proc Route.Process()
1. RouteGradient := GetRelativeGoalOrientation() //Work out the 'angle' from the robot facing straight up to the goal as the crow flies. If there are no obstructions, this is the fastest route and trunc it to either of:
-1.0: Goal is directly to the left
-0.5: Goal is diagonally up to the left
+/- 0: Goal is straight up
+0.5: Goal is diagonally up to the right
+1.0: Goal is directly to the right
2. If RouteGradient > 1 or <-1 then
2.1 (Rotate180)
2.2 RouteGradient := GetRelativeGoalOrientation()
2.3 if RouteGradient > 1 or < -1 then
2.3.1 You have arrived
3. TryDirection := RouteGradient - 0.5 //we add 0.5 on the first cycle of the while loop
3. CanAdvance := False //forgot to set so 2 number 3s.... sorry :D
4. while CanAdvance = False do
4.0 TryDirection += 0.5
4.1 if GlobalBinaryMap[ RobotPositionX + round(RouteGradientToChangeInX), RobotPositionX + round(RouteGradientToChangeInX)] = false then //convert our TryDirection to a vector type deal...
4.1.1 AddWayPoint(RobotPositionX + round(RouteGradientToChangeInX), RobotPositionX + round(RouteGradientToChangeInX)) //adds a waypoint for that empty 'cell' in the 2D array as the path to follow. ALSO flips the bit at that position in the local array to say its part of the route.
4.1.2 CanAdvance := True
5. If LastWayPointIsAtGoal = false then
5.1 Process() //please use a loop rather than this... I'm lazy :D
end;

proc Route.Optimize
This is getting long so heres the deal: ::)
Follow the routes waypoints and each waypoint check if any adjacent cells are not empty. If so, we have a shortcut so find which waypoint to jump to and wipe everything in between. Update the 2d array at the same time.
Rerun as you like as it 'smooths' the route though can be CPU intensive...

end;


Long confusing and personally I have similar - though longer - pseudocode on paper in a messier font of my own hand since I've never had to implement it... My enemies always go from point to point and I collision detect so... Enjoy - and if there are any question fire away :D

Sorry for the long post guys :)

Edit: seeing this makes me wish we had syntax highlighting in that... even just a little bit :D ...and maybe I should code it up, and make it look nice as an article for the PGD library too O.o

User137
07-09-2012, 04:56 AM
I think i might be able to make heuristic node finding. What i looked, was that A* general version gets the perfect path, but it can come at a great cost. Current algorithm already reminds A* actually, if i understood the logic from wiki. I'm not yet completely clear on how it selects the final path in the end. Maybe that goes from goal to start, by the node weights. Just thought about it... Definitely not possible to use weights from start to end.

But also i have thought of a optimization trick for the already visited nodes. I can have "Visited: byte", instead of bool. I don't need to clear every node before search, i can simply increment the comparison value once when search starts, and then set that when visiting nodes. ...
*scratches head* Scrap that :D I could come across search paths which have been left unused for 255 search turns, and mess up next search. It really depends on needed path.
So my current optimization feels most viable, where i write false to visited node each time 1 is removed from search at the end. Still no full map-clear begin of search. I mean, the search arrays are best to keep allocated in memory all times. Using function variables would be a waste of precious cpu-time.

edit: Also, 3D is more complicated for path finding when you consider flying. Maybe it's a high step that you can only jump down, but not go up. So for some part it would be best for programmer himself to make path finding that best fits his game. Simple 3D-path finding with grid, expanded from my current one might aswell consider air tiles as "walkable" places, fitting to make path to. That is naturally wrong... Nodes are smarter in that sense. But maybe it would still need some sort of maximum and minimum Y angles for nodes, to consider moving possibilities. Some character might be able to jump from high place and glide down, but some would die and so should not be possible path to take.

Other solution might be link properties, or just making more pathing maps per world for each case. And still, i am very curious if i can implement pathing map generation at least for 2D. That is way more difficult for 3D, and almost feels impossible to generalize.

SilverWarior
07-09-2012, 07:18 AM
I don't think you need to make more pathing maps if you use nodes. The best think about nodes is that each node contains information about pathways to other nodes. This pathways don't need to be leading only to adjenct nodes but can actually lead to any node. This might come in handy esepcialy if you are implementing some kind of portals into game.

For instance lets take next example:
For the sake of easier understanding I will use 2D platformation example.
Lets say that in your game you have tile based map. You have node in each tile. Nodes are conected with pathways. Each node contain cost information.
Each unit is one tile wide and two tile tall. Units are capable of jumping heights.
So now for units capable of jumping one tile up you use pathway which is conecting origin tile with nearby tile which is positioned one up and one left or one up and one right.
For units able of jumping two tiles up you use pathways which conect origin tile with some other tile whose position is two tiles up and one tile left or right.
The same cane be done for using desends.
Now you can limit certain paths to be used only by certain units with pathways cost infromation. You can do this by using pathway cost information. This can be done easily by defining this information into differen ranges. For instance:
1. 1-10 is used only by units which are not capable of jumping
2. 11-20 is use by units capable of jumping one tile high
3. 21-30 is used by units capable of jumping two tiles high
.....
x. 255 is used by units which are capable of slowly gliding down

Now this won't reqiure you to have different pathfinding maps for ach type of unit, but only some aditional pathways between the certain nodes.

User137
19-09-2012, 06:56 PM
There is now a pretty powerful TCamera class, that is capable to simulate everything glTranslate, glRotate and so forth do. 3 different Lookat()-functions, simplest one only taking target-point as parameter, and extracting rest information from its modelview-matrix. This is yet another step to make nxPascal able to do most things by itself, without needing to use OpenGL-header directly. It's propably impossible to completely make engine self-sufficient though, or not worth the effort. If i'd ever want to use custom camera in shaders, that is now possible.

New TCamera is now used in Model and Picking demos, which now has nearest focused object clickable. It didn't come clear in earlier demo how to prioritize if mouse-ray passes through many objects.

Another helpful change is changing all angle-parameters in math functions to either degrees or radians. Less guessing...

hwnd
19-09-2012, 08:16 PM
Very nice.

What do you think, are these changes or this new camera help me make the camera thing i asked you by PM, more easily now? Do you recommend me to use this new camera instead of directly using glRotatef and glTranslatef ?

User137
20-09-2012, 07:02 AM
That is up to you, i know i will now on use the camera on every project even if it's just 2D. Commands used for camera are really almost same syntax as those OpenGL commands, but there is last parameter doSet: boolean (true by default), which also applies the camera changes to OpenGL modelview. doSet being false, it only changes camera internally. It is recommended to use doSet (or SetCamera manually) only once before rendering or mouse-ray reading starts happening.

You can have multiple cameras. Camera can Push/Pop too, but having 2 instances of modelview is totally different thing. Where in OpenGL you go glLoadIdentity, glTranslate, glRotate on every frame, but with camera you can simply do camera.SetCamera and that would be all there is to it. It can be moved in timed or mouse events and so on.

But also with doSet true you can call OpenGL matrix functions inbetween. I guess example is needed:

cam.SetCamera;
glRotatef(45, 0, 1, 0); // Now the rotation is going directly to OpenGL, camera doesn't know about it
model.Render;
cam.GetFromModelView; // You can read the OpenGL changes into camera, so it can continue where it left
... assume something more happens here ...
cam.SetCamera;
model.Render; // Now it's rendered in same spot again. If i didn't call GetFromModelView, it would go -45 degrees other way.

Lastly, i intend to add camera pathing, possibly using Catmull-rom. Also maybe i could give it possibility to add camera slots, so you could save and load positions without making multiple TCamera.
edit: Added all that in new SVN version. There's 3 camera-interpolation modes: linear, smooth, catmull.

User137
17-10-2012, 01:04 AM
Started (and almost finished) a little game project with nxPascal today - Blocksmasher. I am well aware of copyright issues regarding Tetris. I didn't name my project as such, it is extremely simple and must not be used for commercial purposes. Educational or private entertainment only.

Screenshot:
https://docs.google.com/open?id=0B7FII3MhcAHJT2RlUVhxVkk4bEE

Source code (select File->Download):
https://docs.google.com/file/d/0B7FII3MhcAHJQ3hLSlBUMkluXzQ/edit

Oh, as always please let me know if this or any nxPascal project doesn't compile and run as is. Especially nxPascal demos should compile straight away without modifying anything at all (just Delphi needs path set once for "nx\src\", Lazarus should have even all that already set).

JC_
17-11-2012, 11:07 AM
i really like your unit and here are my two question:

1) How start application in fullscreen ?
2) Generation font take a (little) time at application startup, is possible load font texture from file ?

User137
18-11-2012, 07:19 AM
Sorry, there is no easy answer to either of them. Not something i have tested or needed.

1) I was hoping LazOpenGLContext would have had fullscreen property, but it doesn't. Lazarus crew propably relied on SDL with it, of which i have no experience. It is possible to adapt SDL window and use nxPascal with it in NX_CUSTOM_WINDOW mode, explained in demos and begin of nxGL.pas, but this specific window i haven't tested.

So what remains is non-crossplatform ways, like directly using WinAPI. Maximizing window, showing it on top of everything and hiding taskbar. As you can imagine that doesn't cope well with Linux with multiple taskbars and other widgetsets.
There was some discussion for windows (http://social.msdn.microsoft.com/Forums/da-DK/vclanguage/thread/6c9d9442-2a58-4477-bd68-7aae4dece23c). You can find more with search terms something like "delphi fullscreen graphics". Maybe if it's something simple, i might integrate it to nxPascal itself.

2) At this point there is no font saving or loading. There is another inherited constructor to TGLFont class, which takes just texture-size as parameter (must be square), but loading just that you can't tell how wide each character is. That needs to be loaded from file, or calculated on load from TCanvas fonts. Relevant data goes to charW: array[32..255] of shortint; and textureI: integer; which is index to manually loaded font texture (which is only needed if you want to call font's SetTexture-method). Basically the font class itself supports any kind of fonts, even if they don't exist in Windows system at all. To use such fonts, an editor should propably created, or possibility to use some existing font format of other editor, that includes texture file.

JC_
18-11-2012, 11:04 AM
no problem, thanks for answers

1) Unfortunately maximizing window is not solution for performance. Full scrreen mode give more FPS and i think picture looks more "stable" (less flickering). For development this is not important, but in the final product would be missing. Bad if its possible only with third-party party libraries like SDL, glut etc. In future i will try it.

2) Ok, i plan add texture atlas, font is same

LP
18-11-2012, 02:23 PM
So what remains is non-crossplatform ways, like directly using WinAPI. Maximizing window, showing it on top of everything and hiding taskbar.
You don't need to hide taskbar. Once you set window to cover the entire screen area, the taskbar is hidden by default.


1) Unfortunately maximizing window is not solution for performance. Full scrreen mode give more FPS and i think picture looks more "stable" (less flickering). For development this is not important, but in the final product would be missing. Bad if its possible only with third-party party libraries like SDL, glut etc. In future i will try it.
In our experiments, there is absolutely no performance difference between exclusive full-screen and non-exclusive full-screen modes. In exclusive full-screen mode you get one less copy operation, but even on Intel integrated cards this is not a problem. Most video players go non-exclusive route anyway as to not mess up with your display. So, FPS is basically the same. Regarding "stable" picture and flickering - as long as you enable VSync, it is exactly the same also.

Exclusive full-screen mode was important roughly 10 years ago when video card's memory was still relatively slow, so to save one BitBlt operation. Now, when you would use pixel shaders for advanced effects such as shadows and reflections, a single blit/copy operation's impact on performance is negligible. In fact, exclusive full-screen mode can be considered now quite intrusive as it can be harmful to multiple desktop configuration and switching between exclusive and non-exclusive modes can produce flicker and mess up with your desktop.

P.S. Although, doing rendering in very high resolutions and non-exclusive full-screen mode may still have quite an impact on video memory usage, and even on blit operation, especially considering retina displays getting common these days. But this is the same problem traditional non-full-screen applications need to overcome as well.

SilverWarior
19-11-2012, 05:50 AM
In our experiments, there is absolutely no performance difference between exclusive full-screen and non-exclusive full-screen modes. In exclusive full-screen mode you get one less copy operation, but even on Intel integrated cards this is not a problem. Most video players go non-exclusive route anyway as to not mess up with your display. So, FPS is basically the same. Regarding "stable" picture and flickering - as long as you enable VSync, it is exactly the same also.

I disagre with this. As you probably know AERO desktop on Windows Vista and newer save contents of each whole window (window texture) from every non minimized program which is running. And theese are stored in Graphic Memory. This means that more programs you are running higher is GPU memory consumption. For instance on my laptop I curently have two active programs running (Winamp and Proces Explorer from Sysinternals). So curently my Graphic memory consumtion is 37,8 MB. Sure this seems almost nothing compared to 512 MB of Graphic memory but if I open more programs Graphics memory consumption will increase.
For instance opening notepad increases Graphic memory consumtion to 39,3 MB and just Maksimizing notepad raises Graphic memory consumtion to 41,8 BM. So you see how quickly can you fill up large protions of Graphic memory.
And since computer games often require large amounts of Graphic memory you will want to make as much of graphic memory available to them as posible. And you actually do this by running your game in FullScreen mode as this causes Windows to move all information for other programs from Graphic memory either to RAM or into Swap Page (usually RAM but can be later moved into swap if RAM consumption increases).
Another thing in AERO desktop is that window contents (window textures) are updated even if this window is behind some other window (not shown directly). Eventually this means that more windows are open more work is needed for graphic card to update contents of all of theese textures.
So yes running some game in Windowed mode could hurt it's performance if you have other programs open at the same time.
On Windows XP and older there was not much problem with this as only visible pats of each window were updatet at any time and there was only one texture used for whole screen (more when some applications were using overlay surfaces).
Sure it is posible to temporary disable AERO desktop on Windows Vista and newer but from my expirience this can cause even more problems as you need to make sure that swiching from your application will reenable AERO desktop and then switching back will disable it again. And in case of application crashing aero desktop might not get reenabled properly. So user reloging or system restart is needed.
Also tranzition between AERO desktop and clasic desktop can take even to few seconds of time depending on the number of open programs.
So using this approach isn't recomended. It is only included in newest Windows versions as backward compatibility for some older programs.


In fact, exclusive full-screen mode can be considered now quite intrusive as it can be harmful to multiple desktop configuration and switching between exclusive and non-exclusive modes can produce flicker and mess up with your desktop.

Yes I agree that it can be a bit intrusive becouse if you use multiple monitors they will just go blank. This is due the fact I wrote above when in FullScreen mode windows only process window changes of the application which is ran in FullScreen mode.
As for flickering this is only present becouse Windows needs to move some data (window textures) from normal meory back to Graphic Memory so that it can be used for rendering other applications windows.
And on Windows XP or older there can be a bit more flickering since all windows needs to be redrawn compleetly and we all know how slow canvas redraws are. (GUI from Windows XP and older is canvas dependant while Windows Vista and newer using Aero desktop means that whole GUI is DirectX overlay surface based which alows much faster redraws).

User137
19-11-2012, 09:36 AM
Actually, for every game that i play, i use windowed mode. Be it most can do it maximized windowed mode (taskbar appear behind game window). I should propably research how to do that, be it i'm propably having to IFDEF it to windows only. Anyway, the speed at which you can Alt+Tab when your game resolution is same as desktop resolution, is very fast. In addition you can use webbrowser or music player on top of your game screen. It's a huge benefit. I have never seen any actual performance gain when using desktop resolution fullscreen mode.

Have you played Skyrim? It's one example of games that do fullscreen mode BAD! Apparently the whole "fullscreen mode" subject is not so self-explanatory for many official game engines. When you alt+tab back in game, it only shows you black screen. You have to alt+tab again for it to switch to game screen, incredibly annoying, especially if you have many windows open. I just want to stay the furthest away from fullscreens as possible. Then there are many more games that can simply just crash when you switch to fullscreen mode. Windows OS has very obviously never been made for that kind of display state change.

As for font issue, there are options to go, but maybe the best one is:
Make commands nx.CreateAndSaveFont() which you call just once, and nx.LoadFont(). I could make for example format .nxf, which would stream in the font widths and texture data with compression stream. I have already practised its use in nxData. It would be simple to have everything of 1 font in 1 file, instead of separate image and data files. Besides there is no simple code to save PNG in both Delphi and Lazarus. Added benefit is that the texture data would be straight in OpenGL compatible mode, making the loading much faster than from PNG.

Carver413
19-11-2012, 10:32 AM
I am using freetype2 to create texture maps on the fly. I'm not having any delays so why not just use that ?

User137
19-11-2012, 05:40 PM
I don't know anything about freetype2. There isn't much of information with google either. I find TFontManager class in fpc, but seems cryptic. Are you really sure it's faster? It might support more font types though. Not all fonts can be drawn to TCanvas. (Also this wouldn't fit in Delphi right?)

Size 9 "Arial"-font with full character table loading takes, with different texture sizes:
256 -> 109ms
512 -> 374ms
1024 -> 1500ms
You should always use smallest possible texture size, where characters still fit in. I managed to optimize bitmap loading slightly for fpc, but the numbers were pretty same as before.

Font saving to bitmap already exists, through setting nxGraph.NX_SaveFontBitmap:=true; , it will save it to 'FontBitmap.bmp' when loaded.

Carver413
19-11-2012, 06:27 PM
I really have no idea whether it is faster, 1500 ms doesn't seem like it is worth worring about. I create one very long bitmap and use it that way but I dont use opengl to render my gui but rather send the final product to opengl. this way it only needs to be redrawn if something changes and because there are so many effects that can be applyed that I could not do in opengl at this time. some day perhaps. anyway the documentation on the freetype2 website is really good and is what I used. I found the fpc solution rather overkill myself. one of the commands was missing from the pascal header so I had to add that in myself.

LP
19-11-2012, 09:40 PM
As you probably know AERO desktop on Windows Vista and newer save contents of each whole window (window texture) from every non minimized program which is running. And theese are stored in Graphic Memory. This means that more programs you are running higher is GPU memory consumption.
Since you are talking about AERO, please check WDDM (http://en.wikipedia.org/wiki/Windows_Display_Driver_Model), which allows video memory paging. What this means is that technically the video memory is not bound by the limitations you explained. In other words, you may stop worrying that you'll end up without video memory on Vista+. ;)



As for flickering this is only present becouse Windows needs to move some data (window textures) from normal meory back to Graphic Memory so that it can be used for rendering other applications windows.
And on Windows XP or older there can be a bit more flickering since all windows needs to be redrawn compleetly and we all know how slow canvas redraws are.
Flickering is caused by rendering being out of sync with vertical retrace, therefore enabling VSync resolves the issues in most cases. Please do not confuse or mix Windows XP and Windows Vista+, as the two use very different approaches and completely different driver models.



(GUI from Windows XP and older is canvas dependant while Windows Vista and newer using Aero desktop means that whole GUI is DirectX overlay surface based which alows much faster redraws).
Not according to the following:



In Windows Vista, all Windows applications including GDI and GDI+ applications run in the new compositing engine, Desktop Window Manager which is built atop the Windows Display Driver Model. The GDI render path is redirected through DWM, and GDI is no longer hardware-accelerated by the video card driver. [4][5] However, due to the nature of desktop composition (internal management of moving bitmaps and transparency and anti-aliasing of GDI+ being handled at the DWM core), operations like window moves can be faster or more responsive because underlying content does not need to be re-rendered by the application.

Actually, it's Windows 7 that brings back hardware acceleration to GDI, but on Windows Vista it's made entirely in software. [Reference] (http://en.wikipedia.org/wiki/Graphics_Device_Interface)

SilverWarior
20-11-2012, 09:05 PM
Since you are talking about AERO, please check WDDM (http://en.wikipedia.org/wiki/Windows_Display_Driver_Model), which allows video memory paging. What this means is that technically the video memory is not bound by the limitations you explained. In other words, you may stop worrying that you'll end up without video memory on Vista+. ;)

Yes I know this. T
he reason why I havn't mentioned this is becouse we were discusing perofrmance. And if you go and benchmark Grphic card performance when it is only using its internal Graphic memory or when using Extended graphic memory (some data may be loaded in RAM) you will clearly see performance diferences. The rason for this is the fact that Graphic card can read information from its internal graphic memory much faster than reading this information from RAM especially if some other part of your application is heavily utilizin RAM for some other things.

User137
20-11-2012, 09:46 PM
New SVN version of nxPascal was just uploaded. Among many additions, i did the font saving and loading to file. 1024x1024 texture size courier font loaded up in 30ms... Yeah, that's 3 times faster than it generates a 256x256 font, and 1024 is so big font you rarely need it. The compression stream made font file size to 30kb. To make new font, do:

var f: TGLFont;
...
f:=TGLFont.CreateBMPAndSave('Courier', 50, 1024, 'courierBig.nxf');
// File extension doesn't matter. Use .nxf for clarity i guess.
f.Free;
Loading goes simply:

nx.LoadFont('courierBig.nxf');

JC_
21-11-2012, 06:10 PM
@User137 perfect, thanks

@Full screen discussion, ok ok, maybe I'm thinking too anachronistic :)

User137
23-11-2012, 11:01 AM
Hey, i tried to do the windowed fullscreen mode and it worked. Just need to do things in this order:


BorderStyle:=bsNone;
WindowState:=wsMaximized;
nx.CreateGlWindow(self);
If you do nx.CreateGlWindow() before those 2 lines, you need to KillGLWindow and CreateGlWindow again or you get white textures. And i'm not entirely sure if already loaded textures will remain loaded, or if you have to load them again. Who knows that might depend on graphics card. You are basically resetting rendering context so...

Above code will simply make game window fill the entire screen (not even taskbar shows, until alt+tab). It can't alter the resolution. For that you can use scaling of the graphics. In the end what matters is how many things you draw. You can make a 320x200 picture fill the entire 1680x1050 screen, and disable linear filtering to get that retro-look, if needed. Not sure if i explained that in wiki, but it's done with:

uses ... , dglOpenGL;
...
tex.TextureQuality:=GL_NEAREST; // Blocky textures
tex.TextureQuality:=GL_LINEAR; // Smooth textures
It is a mode that must be set before loading 1 or more textures, and can be changed per each one.

User137
12-12-2012, 10:22 AM
Not too many news on nxPascal this time, very busy with school things, at least in theory.

3D-Editor is progressing bit by bit. There is already 1 old version i made with Delphi, but i want to redo it with Lazarus along with many new features. Just vague list of things in progress and to come:
- Saving and loading all nxPascal supported model formats - done.
- Loading many models at the time, and creating multiple instances of them in the scene - done, just for viewing.
- Interface design is big ongoing work, deciding on how to access each feature easiest way. That's maybe the hardest part.

I had 1 setback that loading the demo ship model took about 20 seconds when debugging, but 1 second when run on .exe, but that's fixed now.
Note to self: Do NOT! Ever! ..check "Generate code for valgrind (-gv)" in project options.

Always looking for more developers to assist with coding too.

hwnd
29-01-2013, 11:11 AM
Hey.

Atm in your picking demo the engine is initialized in FormCreate event.
But i want to init it by button click. But for some reason it doesn't work. If i move
if not nx.CreateGlWindow(self) then begin
showmessage('Failed to initialize OpenGL!'); exit;
end;

to Button1Click event and click the button, nothing happens, it does something but the black screen doesn't appear (i.e OpenGL doesn't initialize) but if i move this to FormCreate, i run the app and get that black screen without problems (OpenGL initialized fine).

If i shut down the engine in my buttonclick with
if game<>nil then FreeAndNil(game);
nx.KillGLWindow;

and then call
if not nx.CreateGlWindow(self) then begin
showmessage('Failed to initialize OpenGL!'); exit;
end;

Then it initializes also with ButtonClick.
Why is that?
What's so special about FormCreate?

Initializing the engine in formcreate and then shutting down again to init it again when user opens a map is not way to go for me.

Is this a bug?

User137
29-01-2013, 02:15 PM
There's propably bug in your code. I get black screen and green rectangle with this code, using TButton and TTimer (enabled and 17 interval):

procedure TForm1.Button1Click(Sender: TObject);
begin
if not nx.Initialized then
nx.CreateGlWindow(self);
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
nx.KillGLWindow;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if not nx.AllOK then exit;
nx.Clear(true, true);
nx.Enable2D(0, 0, nx.Width, nx.Height);
nx.SetColor(0, 1, 0);
nx.RectT(10, 10, 110, 110);
nx.Disable2D;
nx.Flip;
end;
It just took over 1 second to initialize on button click.

Oh, if i recall the picking demo also uses onPaint event after onCreate? You need to do those in the click event too, and not when app initially does Paint first time.

SilverWarior
29-01-2013, 02:34 PM
Hey.

Atm in your picking demo the engine is initialized in FormCreate event.
But i want to init it by button click. But for some reason it doesn't work. If i move

if not nx.CreateGlWindow(self) then begin
showmessage('Failed to initialize OpenGL!'); exit;
end;

to Button1Click event and click the button, nothing happens, it does something but the black screen doesn't appear (i.e OpenGL doesn't initialize) but if i move this to FormCreate, i run the app and get that black screen without problems (OpenGL initialized fine).


Wait doesn't "self" in Button-s OnClick event points to the buton which fired that OnClick event? From what I see you are trying to force nxPascal to use TButtom as rendering targe which probably won't work.
Try replacing "self" with the name of your Form. For instance:

if not nx.CreateGlWindow(MainForm) then begin
showmessage('Failed to initialize OpenGL!'); exit;
end;
NOTE: This is just my speculation (haven't got any real expirience with nxPascal) so it might not work.

User137
29-01-2013, 02:57 PM
Wait doesn't "self" in Button-s OnClick event points to the buton which fired that OnClick event? From what I see you are trying to force nxPascal to use TButtom as rendering targe which probably won't work.
Try replacing "self" with the name of your Form.
Nope, it is TForm1.Button1Click(Sender: TObject); so self refers to main form variable (Sender refers to Button1). But good point. nxPascal uses form information to use it as parent to TLazOpenGLContext, and copy onMouseMove events and so on from TForm to the context. (Delphi implementation differs internally, cause it doesn't have the context component at all.)

hwnd
29-01-2013, 09:08 PM
Oh, if i recall the picking demo also uses onPaint event after onCreate? You need to do those in the click event too, and not when app initially does Paint first time.

I dont use any TTimers, i use your picking demo as "core". TTimers are ugly.
The most they can push out is 16ms, if even that. Your nxPascal uses better method: "game loop".
I used also TTimer until i found nxPascal and now im happy user of game loop.

I will try that onpaint thingy.

hwnd
29-01-2013, 09:40 PM
OK, it works if i make it with OnPaint code. This looks fine to you? Add / remove anything?

If i use this, do i still have to use the code in OnPaint or i can remove it from there now?
Currently i commented this out in OnPaint. Seems to work fine.


procedure TfrmMain.InitEngine(Ctrl: TWinControl);
begin
if not nx.CreateGlWindow(ctrl) then
begin
ShowMessage('Failed to initialize OpenGL!'); Exit;
end;

// Create game
if (game=nil) and nx.AllOK then begin
game:=TGraphicalGame.Create;
if not game.Initialized then begin
FreeAndNil(game);
showmessage('Game failed to initialize!');
exit;
end;
end;

pnlRenderResize(Self);
end;

I will use this now.

User137
30-01-2013, 02:56 AM
1) Why do you need to reinitialize rendering context other way than usual, application start? Notice that you will lose all loaded textures when doing so. If TGraphicalGame was freed properly, it will recreate them in constructor as should. For something like using multiple "rendering windows", this sort of behavior is not needed at least. OpenGL can quickly switch between rendering contexts. That's again going to territory i haven't tested, and implementation differs on Delphi and Lazarus.

2) You will be ok without the onPaint. In the constructor of TGraphicalGame, it might be calling CenterMouse() if you want to make for example FPS game, or space simulator like that picking demo. onFormCreate does not know much about window size and position yet, so it would give mouse a random "warp" effect at start... That's why TGraphicalGame should only be created once the window exists and is visible.
For example, if form1.Position is poScreenCenter, it is only made effective at onPaint the earliest. onFormCreate and even onShow still don't know the real values.

hwnd
30-01-2013, 09:18 PM
I don't care about reloading textures, i work with tiles of 64x64 and i have my own cache system that loads and deletes textures from memory, if they are needed, they are always automatically loaded. User wouldn't even notice that textures were removed or reloaded.

I don't need to init OpenGL immediately in FormCreate if user opens the map, then i will init the opengl. Otherwise there is no point. For games this of course is fine, but im working on a map editor and not a game. I need to have control over things. The code in previous post works fine so i will use it.

Of course for any game i will make i will leave things as you did in your examples. At least the initializing.
But yes, for map editor i must do things differently.

User137
30-01-2013, 11:06 PM
I don't know any map editor (or any other software) in existence which would discard rendering context :) Not even Starcraft 2 map editor when there is only trigger/script editor window open. Exception is fullscreen resolution change.

At the meantime with nxPascal, work on Edit3D has continued. Solved the polygon picking and other matrix math for all cursor controls. Camera, objects and selected vertices can be moved and rotated. Selection with rectangle region, using gluProject(). Periodic fighting with small bugs etc... in editor code that is. It is very very rare occasion that i find bugs in nxPascal core. There are still 0 known ones.

hwnd
20-02-2013, 01:08 AM
Is it possible to load "tex" textures from memory? (Pointer).
Atm i see only "LoadFromFile" or "FileName" everywhere.
If there isn't, you should add this possibility to load texture data from pointer.
User will supply W, H and maybe transparency (on, off) and bits.

I tried right now to mess with these NPOT textures to see how your engine handles that and im unable to load texture from pointer.
I will temporarly try to load it from BMP and see how it works. If it will work..
I tried to render something NPOT and i see only black box or even nothing. Dunno, maybe my code is faulty.
But tile loading which are 64x64 is ok. I modified it for NPOT sprites.

User137
20-02-2013, 02:19 AM
It should be possible to load from TBitmap. What happens when texture is loaded from file:
1) New texture record is created to the array, via AddTexture(). If you leave filename empty, it will skip the texture loading but keep the empty record for your use.
- Internally this will fill the record's Data pointer. You can see more TTexture details in nxGraph if you wish. Most of that is relevant for next part. For example if your data would be only RGB (in that specific order 3 bytes per pixel), then you need to set:
values=3, format=GL_RGB, intFormat=GL_RGB. Then the sizeX, sizeY, Width, Height by your image.

2) Calling Restore() will push the data from pointer into OpenGL's memory. Unless you set toKeepData for texture loading options, it will free the data from pointer.

If you would have a more general function in mind that i could make to simplify all this, i'm open to suggestions. I don't know.. like this?

function AddTexture(name: string; data: pointer; width, height, values, format: integer): integer; overload;
Internally some images might have reverse order of bytes, such as BGRA. Therefore format should propably be given, as long as it's found from GL header. At least you don't need to worry about linear/nearest or mipmapping, that's already dealt with the loading options and Restore() for you.

hwnd
20-02-2013, 10:32 AM
Yep, such overloaded function would be very nice.
I looked around in sources and found the struct, but i don't know if i may be able to try it out today.
Maybe after work.

But as i said such function will not hurt.

hwnd
24-02-2013, 01:59 PM
@User137

Is the path finding in nxPath OK to use?
Too bad that it doesn't have enough comments and / or example included.
I would like to use it for simple tests but this "node" thing seems pretty complicated for me and i don't know how to fill in parameters.

User137
25-02-2013, 12:23 AM
Did you check the pathing demo? It is ok to use but it will not work if you have several heights or unnatural shapes. It is only made for flat tile-world for now.

pathfinder:=TTilePath.Create;
pathfinder.SetMap(cMap, W, H);
pathfinder.SetCell(x, y, 1); // 0 is passable, 1 is wall
// Then you call
pathfinder.GetBetterPath()
...which fills TPath record for you. Count of nodes and array of TPoint, from index 0 beginning to end.

hwnd
25-02-2013, 09:23 PM
Sorry.
I didn't notice the pathfind demo. And again because i code in very late at night, im tired and sleepy.
I should sleep at nights. But i come from work, eat, and turn my pc on and when sun slowly rises i go to sleep.

But what is the difference between GetPath and GetBetterPath?
One finds "blocky" path to target and other one with "smooth curves" or direct?

User137
25-02-2013, 10:41 PM
The pathfinding algorithm is heuristic for high speed, never attempts to find a perfect path, and that should be cool for most games. There are cases where path is more optimal when search is started from end to start, instead of start to end. GetBetterPath() makes attempt from both directions and returns the shorter. (And because of that, it is a little slower. Although in the case of pitiful small map like 64x64 or so, it is practically instant.)

Either way, i have tested the algorithm on very complicated labyrinths, and even on a loooong spiral map. It does find the path in all the cases, unless the maximum node allocation is reached. It is quite high by default.

hwnd
26-02-2013, 01:02 AM
Real flat tiles is ok for now. I just want to test some of my ideas.
2D is (almost) always simpler to start with.
If i cant make 2D to work, there is no point for me to try 3D.
Thanks.

I will let you know if i will work out something.

hwnd
27-02-2013, 01:12 AM
Let's say i have two cones in the scene and one of them must point to another cone.
And it should do this smoothly ( i mean turning ).

If i understand it correctly i need a way to find angle (difference) or something between 2 points (X,Y) and then rotate until one cone is pointed "looking" at (to) another cone. I must somehow align one vector to another.

Is there any command that makes these things easier?

User137
27-02-2013, 02:23 AM
In the unit nxMath, 2 overloaded versions of Angle():

function Angle(const px1,py1,px2,py2: single): single; overload;
function Angle(srcRadian, destRadian: single): single; overload;
First one finds angle from source point to target point, and the other function tells which way to turn.

PS. You could use Skype/MSN chat for these small questions too.

User137
27-02-2013, 10:28 PM
I figured how i could combine 2 things i have wanted, firstly making a FPS game demo. And secondly generating some or all textures to it on the fly, and loading them in using new data pointer. I still have no real tool for 3D animation so i'm going to have to use my old Edit3D and frame animation, if needed. I expect no less from the demo, than being able to run around on a triangle map with collisions, and bullets leaving particles on the walls. Could try some collectibles and interactable objects such as door button.

hwnd
27-02-2013, 10:52 PM
Wow, that demo would be awesome.
I think you have read my mind with this. I had a plan to do something similar.
Actually porting one C++ fps tutorial code to nxPascal.

Go ahead, you can do it better. Hopefully you will not use a lot of shaders.
I personally don't like them.

Your Edit3D allows to do frame animation?

BTW, thanks for the tip above.

User137
27-02-2013, 11:49 PM
With the old Edit3D it's possible to first create for example humanoid, and then copy/paste it multiple times. Then move vertices to make it seem like animation. Frame animation is much simpler than joints, and i have used that some year ago. Difficult to say its current status. Interpolated rendering functions seem to exist, and W3D loading automatically loads and fills the frame array for TTriModel, by quick glance.

Created quick and dirty level screenshot :D

And added first ingame screen. Now it's pretty safe to say that model loading could use some tweaking... Either way, moving without collision, jumping and aiming works. Laser sight on the rifle looks also pretty cool, it's large dot on close wall, and tiny dot at distant. And that gun there is rotating and floating, rendered after a glowing sprite which turns towards camera.

edit2: Collisions finally working right. Custom made "physics simulation" sort of. Gravity is constantly affecting the character, and he is pushed away from nearest wall point, be it floor most of the time. This makes it possible to simply walk on top of that pile of rocks, or in other terms you could climb stairs with this. I can't wait to give you a video out, but there's still more things to do.

hwnd
28-02-2013, 08:39 AM
Interesting way for collisions. Ok gravity for floors but for walls, never heard about this. Interesting.
Will wait for the video.

SilverWarior
28-02-2013, 09:20 AM
Gravity is constantly affecting the character, and he is pushed away from nearest wall point, be it floor most of the time.

Wouldn't this mean that when you are on the slope you would also be pushed back at the same time and not only up? Wouldn't this prevent you from standing on the slope?

User137
28-02-2013, 03:06 PM
Yes it kind of does, player slides down slowly. Now it's good enough to publish a video. I also released it on SVN, both Lazarus and Delphi demos:

http://www.youtube.com/watch?v=dbwRfr1_QRw
Collisions, sounds, pickable objects (player starts without weapon), jump, crouch. Pretty happy for 1 day's work 8)

That texture bug still bothers though. It is not renderer's fault, it's just that my W3D format saves unique texture indices per face vertex. nxModel loader attempts to merge and group mainly based on smoothing groups. The texture coordinates are sort of right, some of them should just duplicate the vertices, to use the unique texture coords. The way these textures repeat in my world model makes it calculate them wrong. It really won't be easy to fix i think.

edit: Well, i uncommented some older code and the texture bug was gone with it. I'll keep it that way but hope that other issues won't rise by it.

SilverWarior
28-02-2013, 05:26 PM
Nice work. You made all this just in one day?

hwnd
28-02-2013, 09:59 PM
Yep, nice stuff for 1 day.
You could use a bit better texture actually. Pretty hard to see different things.
But these rocks on the floor and going onto them is also very nice thing to see.

I will go download the latest from svn now.

User137
01-03-2013, 08:07 AM
So yeah, the texture bug was fixed. I also added the texture generation on the fly now, for new forcefield and the glow texture. Bullets bounce from the forcefield, player doesn't. I guess this is enough functionality for this demo. If i was to create any more, it would be wiser to have a real level editor and propably some sort of octtree optimization (not something i have in mind to do for long while maybe). This does start to get a bit laggy on my computer when the bullets are in hundreds, and for a good reason. There is over 1200 triangles in the world model, and checking each face per each bullet per frame, does take a bit of time.
1121
As for lighting, i could still maybe optimize it with OpenGL default lights. Without investing too much time into that, because the real intention is to have more powerful lighting arrays for GLSL later on.

User137
02-04-2013, 11:52 PM
Been coding few days on renderer class using shaders. The rendering queue should in theory already work for 2D, but it's not showing anything yet >:( Shader source compiles, all uniforms and attribs are verified to be correctly initialized, i have checked the math on modelview matrices from multiple examples. Either way, once this works, it will have some cool new 2D capabilities. All 2D drawing will have ambient, diffuse and customizable per vertex colors. May have to stop for today, but i'll show some code snippets in faint hope that anyone finds a mistake:
2D Vertex shader:

#version 110

attribute vec2 in_position;
attribute vec2 in_texCoord;
attribute vec4 in_color;
varying vec2 texCoord;
varying vec4 color;
uniform mat4 pmv;

void main() {
texCoord = in_texCoord;
color = in_color;
gl_Position = pmv * vec4(in_position, 0.0, 0.0);
}
2D fragment shader:

#version 110

varying vec2 texCoord;
varying vec4 color;
uniform sampler2D texture;
uniform vec3 ambient;
uniform vec3 diffuse;

void main() {
gl_FragColor = texture2D(texture, texCoord) *
(color * vec4(diffuse, 1.0)) + vec4(ambient, 0.0);
}


T2DVertex = packed record // size 8 float
v: TVector2f;
uv: TVector2f;
color: TfRGBA;
end;

va2D: array of T2DVertex;

Last in constructor:
glBindBuffer(GL_ARRAY_BUFFER, buf2D);
//glBufferData(GL_ARRAY_BUFFER, sizeof(T2DVertex)*length2D, @va2D[0], GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(T2DVertex)*length2D, @va2D[0], GL_DYNAMIC_DRAW); // temporary to see if helps
glVertexAttribPointer(att_2Dpos, 2, GL_FLOAT, false, sizeof(T2DVertex), nil);
glEnableVertexAttribArray(att_2Dpos);
glVertexAttribPointer(att_2Dtex, 2, GL_FLOAT, false, sizeof(T2DVertex), pointer(8));
glEnableVertexAttribArray(att_2Dtex);
glVertexAttribPointer(att_2Dcol, 4, GL_FLOAT, false, sizeof(T2DVertex), pointer(16));
glEnableVertexAttribArray(att_2Dcol);
glBindBuffer(GL_ARRAY_BUFFER, 0);
...

procedure TGLRenderer.SetUniforms;
var pmv, modelM, projM: TMatrix; normal: TMatrix3f;
begin
glGetFloatv(GL_PROJECTION_MATRIX, @projM);
glGetFloatv(GL_MODELVIEW_MATRIX, @modelM);
pmv:=multiply(projM, modelM);
glUniformMatrix4fv(uniPmv2D, 1, bytebool(GL_FALSE), @pmv);
glUniform1i(uniTex2D, 0);
with ambient do glUniform3f(uniAmbient2D, r, g, b);
with diffuse do glUniform3f(uniDiffuse2D, r, g, b);
end;

procedure TGLRenderer.Render;
begin
shader.SelectProgram(0);
glBindBuffer(GL_ARRAY_BUFFER, buf2D);
glDrawArrays(polyMode, 0, vCount());
glBindBuffer(GL_ARRAY_BUFFER, 0);
end;

edit: I tested by drawing with glBegin/glEnd style in Render function (without shader) and it shows. So at least it's not fault in buffer data.

edit2: Fixed ;D Attribs, ambient, diffuse, matrix calculation is all working. Can soon start finishing 3D shader aswell.

User137
08-04-2013, 09:25 AM
Lots of the above code is changed now... I removed ambient color because it didn't feel necessary/useful for 2D, and also moved the color multiplication from fragment to vertex shader for more performance. All in all the rendering queue technique really works, and it's automatically switching the shader program, although i haven't done hard stress tests yet. I have uploaded the recent changes to SVN, where is Draw() and DrawRotateS() implementation for now.

I did my best to make the coding as easy as possible, while also not doing anything unnecessary work in the functions for that. So attached outcome can be gotten with 3 lines of code:


// Draw a quad at (50, 200), pattern 0, facing angle from point to cursor, centered at (0.2, 0.5), with scale 64, 64
index:=renderer.DrawRotateS(50, 200, 0, angle(vector2f(50, 200), playerPos), 0.2, 0.5, 64, 64);
// Returned index is first vertex index for the GL_QUAD. Change that to red. Last vertex would be index+3
renderer.SetColor(index, 1, 0, 0, 1);
// Finally flush the rendering buffer. You can queue up more Draw commands before rendering them.
// If buffer would get full, it will render them automatically, and start the buffer from 0 again.
renderer.Render;

Also i have very strong doubt that the shader queue rendering is much much faster than my previous DrawRotateS() without it. This time the rotation is also done with efficient math, not using glRotate matrix operations.

hwnd
11-04-2013, 09:32 PM
Shader "additions" are only for 2D stuff or they involve your 3D rendering code / stuff also?
I mean, i will have to modify my code after these additions?

Im not against shaders or anything, just curious.

User137
11-04-2013, 09:56 PM
The shader core is "neutral", it is neither 2D or 3D. Renderer class is a higher level implementation of it, that builds at the moment 2 shader programs. 1 for 2D and 1 for 3D, except that i haven't had time to work on the 3D yet. I'm doing some tests with shader code in other project, trying to get point-light system done with maybe 8 lights. So you don't have to modify anything. Everything old still works, this will just be a separate addition to nx. The rendering queue should work for both 2D and 3D, just that 3D shader has all rendering commented out.

About this 3D shader, it has some technical challenges that i would have to solve in theory first aswell, before coding. Because GLSL ES doesn't support dynamic for-loops and IF structures very well, and i can't have large dynamic arrays, how am i supposed to use many lights? There's many questions that still need answered, but for now it seems that i would have to have static 8 lights and just turn them black color... Then i would let renderer know 8 nearest lights to camera + environment lights ambient/diffuse/specular stuff. But for now i'm not done with the matrix math yet. I need to construct NormalMatrix and so on, to get even 1 light working first. And i haven't been able to do that with the default gl_NormalMatrix etc yet.

hwnd
11-04-2013, 11:48 PM
Thank you for the reply.
Hopefully you will sort this out. You have been doing very good stuff so far and i am pretty sure that you will get things working.

Too bad i can't help because i don't know much about shaders. They are still very strange things for me, like some magical black boxes that do "awesome visual things" somehow. I don't even know how to make simplest effect.

Hopefully one day i will pick them up.

Best of luck!

hwnd
13-04-2013, 09:53 PM
How can i detect in nxPascal if the mouse is moved by user and specific mouse button is held down at the same time?
I mean like dragging.

How i ever figure out with nxPascal that mouse moved?

It was easy with forms, but what about nxPascal?
Seems impossible to me or very hard.

Is it even good idea that i want to process all mouse stuff in AppEventsIdle?
Or i should continue using standard Delphi events like "MouseMove" etc or move mouse stuff also into game.loop?

I have keyboard (only arrow keys) processing in game.loop atm.

User137
14-04-2013, 05:27 AM
For the mousedown/up you should use the form onMouseDown event. You should check the gametemplate demo, it moves the glowing orb with mouse. And when mouse is held down, it's showing as different color. Basically you should only use the Delphi's mouse-events when there are no other options. There is no other difference to it than keeping the code cleaner, by having ingame events coded in the gameunit. There are things that Delphi's form events can't do by default, and that is getting the mouse delta, keeping the cursor centered on form in FPS games, changing mouse sensitivity and so on. Those are what nxPascal does with its mouse variables.

rferriz
19-04-2013, 03:13 PM
Hi User137,
What platforms currently supports nxPascal ?
Do you have plans to support any mobile platforms? Like android / iOS

Also I did not found any doc or roadmap ... is there anyone or you just do as you like?

Congratulations, seems pretty powerfull engine.

Edited: Just found wiki, its enought doc to start :D

User137
19-04-2013, 11:46 PM
Well, i am the only developer and i don't really receive much/any feedback at all on what it can do, or what it should be able to do. I'm under assumption that nxPascal works on Windows, Linux and maybe Mac, with Delphi and Lazarus. Of course if that wasn't true, i also assume people would tell me error reports about it, even smallest compiler warnings. This simply because i am using crossplatform units of Lazarus, and any hints to Windows unit are conditionalized for Delphi only. I do not have Android/iOS to test with, nor anybody that would be able to test for me, so i haven't looked into it yet.

Yeah the wiki is something at least, but again it's 1 of the things also that i haven't received any feedback of thus far :p I am not sure what things people would most want more information about. Some of the units may have changed abit since writing those pages.

hwnd
20-04-2013, 12:16 PM
If there is no feedback then it means that there are no bugs and all required features are implemented.
People are enjoying them. Like me.
But of course bugs should be reported and features requested. I have reported some of them and even requested features which you have implemented / modified. Thanks!!


But if we talk about Android, then i can test Android stuff a little bit. I have a phone with Android 2.3.6.
But i dont know much about Android. I tried the Eclipse IDEs etc, but my PC is too old and slow to even run the Android emulator. I tried to make few simple apps but that was it.

All in Java.

JC_
21-04-2013, 12:02 PM
For android is very good solution ZenGL - demos, some phone functions, touch, etc. Better is test applications directly on phone or use Linux, there run emulator much better.

I use both, nxPascal for PC, ZenGL for Android

Daikrys
22-04-2013, 04:39 PM
you could also have a look at blue stacks (http://www.bluestacks.com/)

User137
27-05-2013, 06:16 PM
I am propably going to ignore android development for (very long?) time being. There exists programming environments better suited for it. I will focus on the PC. And lets face it, it's the only platform for real gaming. What is going on the market does not concern me, games can be real virtual worlds to complement real life in a fun way. Small portable device is physically incapable of making that as rich experience.

I have been recently making 1 sort of 2D game, but it uses custom shaders. nxPascal can draw terrain with 1 shader, VBO and many texture units, game objects with other shader, and fonts on top with standard OpenGL commands. I did came to realize that switching to a shader is difficult, actually as much that i had to inherit from TGLShader and make a new class for each new shader. It really is that difficult because each has different uniform variables to pass, and different kind of rendering needs, i even needed a different structure in vertex array. Much of that can be copied straight from renderer class though.

So i am a little excited on what this engine could do in right hands. I was thinking of making a small 2D shader demo of a fish aquarium. It would render all first pass in frame buffer, and then render the second pass through a wave shader. It would make all objects within water to wave along with it :)

As always, you can suggest what kind of tutorials or additions you would like to see in nxPascal. How could i emphasize enough, that making simple 2D-game is actually easy, that this engine is new-programmer-friendly? On simplest level it comes down to nx.Draw(x, y), that's enough to draw a whole Pacman game if you wanted to.

JC_
28-05-2013, 08:52 AM
As always, you can suggest what kind of tutorials or additions you would like to see in nxPascal. How could i emphasize enough, that making simple 2D-game is actually easy, that this engine is new-programmer-friendly? On simplest level it comes down to nx.Draw(x, y), that's enough to draw a whole Pacman game if you wanted to.

Thank you for nice work.

I have a few notes:
1) there is no demo for control (mouse and keyboard) - key repeat, key down, key up, keypressed, doubleclick.
2) frame rate limiter is not accurate, is set to 60 FPS but jumping from 62-63. It is a bit problematic in the calculations of moving objects etc. It should be exactly 60 FPS.
3) will be fine basic demo with accurate physics (movement) independent of the framerate

hwnd
20-06-2013, 09:24 PM
Hi.
I don't have much interest in programming lately, because of good sunny weathers, because of different projects on my car etc etc. But today i just tried to rebuild my map editor and Delphi 7 throws me an "Range check error" in nxGL at line 1731, which is: Data[i*4+3]:=255; // Full alpha

I have enabled full range checking etc all that debug stuff. Because i want to see in my project where is leak or where is too much data.

I don't know if you read this or not but you should or could add this code between {R-} and {R+} but better is to fix it, so it's always in range.

Im currently using rev84.

User137
21-06-2013, 02:34 AM
1) there is no demo for control (mouse and keyboard) - key repeat, key down, key up, keypressed, doubleclick.
2) frame rate limiter is not accurate, is set to 60 FPS but jumping from 62-63. It is a bit problematic in the calculations of moving objects etc. It should be exactly 60 FPS.
3) will be fine basic demo with accurate physics (movement) independent of the framerate
Didn't notice this message before. The Picking demo makes use of mouse, keyboard and frame timing. There is a difference between how many times frame is rendered, and how many times gametick is calculated. Frame times can differ because frameskipping is in use by default. However amount of gameticks per second should always be the same on every machine. These are controlled with methods SetFrameInterval() and SetFrameSkipping(). By default the frame interval is set to 16, where 1000/16 makes for 62.5. 1000 is not divisible by exact 60, you would get 16.6666666. But this is closest you get to vsync ratio of 60 fps. Also all this is the reason i made GameTemplate demo :) To make it very easy to start new project, with all the input and frame handling placed ready.

You seem to have different version to mine (3339 lines in nxGL.pas by the way...), i have different code on that line. Also i tried setting range-checking on in Delphi 7, and then called the TGLTextureSet.AddEmptyTexture(), which seems to be function you mean. I don't even get any compiler hints. Not getting any hints in Lazarus either. Delphi code uses SysUtils.PByteArray type for the data array, which means
TByteArray = array[0..32767] of Byte;
Sure, textures like 512x512 with alpha channel use over 1 million bytes of data, and would sure go over boundary.
Would you check if this fixes it?
Data^[i*4+3]:=255;
Because after all we refer to pointer allocated data, not static array. And now that i think about it, it could possibly be replaced with setlength() implementation.

hwnd
21-06-2013, 09:19 AM
Like i said in my previous post im using rev84. Older one. I havent messed with this stuff for months.
Maybe getting the new version will help. Will try it later today or tomorrow. And if this doesnt fix this i will do the texture test.

EDIT: rev86 didnt fix it. So later i will try the texture test. Atm im too busy and gtg.

Murmandamus
21-06-2013, 08:08 PM
If you're using that declaration, then any RGBA texture which is bigger than 8192 pixels (~91x90 pixels!) will cause a range check error. Shouldn't that be a much bigger array, like Array[0..4294967295] Of Byte?

Darkhog
23-06-2013, 10:10 PM
Or better, open array (array of byte) with would be set with SetLength and some formula, like Width*Height*NumOfComponents (where width and height are obvious and NumOfComponents would be 1 for grayscale/indexed bitmaps, 3 for RGB and 4 for RGBA).

User137
25-06-2013, 07:22 PM
Yeah, mentioned it also in my last post. I made some performance testing with allocmem vs setlength, and writing 1024x1024x4 arrays full of data. I couldn't find any notable speed differences, so i went and changed texture data use setlength-type dynamic array. That kind of arrays have always felt to be much more "in the core" of pascal, and i enjoy working with them much more than C-like alloc functions.

SVN is updated with this change, and didn't notice any errors in demos still. It does always remind me about TexSet.LoadFromFile/SaveToFile procedures though. Haven't decided on file format still, but it might go to simple textfile, instead of any XML-like tags, or INI format. For some reason i'm not sure if internal class for ini-files is very optimal. I've just had some odd experiences where it might've taken 3 seconds for 1 tool settings window to close, when it saved a tiny file on hiding it.

hwnd
25-06-2013, 08:36 PM
Ok, i will gonna try again.

By internal you mean the Borland Inifiles.pas or your own?

EDIT: Tested, no more "Range check error". Map editor seems happy also.
Thank You for fixing it quickly.

User137
25-06-2013, 09:27 PM
Not sure of Borland, i meant FPC/Lazarus either one. But it's long ago and i can't replicate it. It was random back then, and i did something "odd" to make the problem go away ^_^ Well, text files are ok. It's just a list of texture filenames, pattern sizes... Also it's been a while since i updated the .zip files, like setting stable version from most recent SVN. I still wish to finish the 3D part of renderer before i do that. Renderer itself was a success, at least for everything i've tried it with 2D, and custom 3D.

User137
02-07-2013, 07:56 PM
I translated Simplex class from: http://staffwww.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java
This is a noise generation algorithm, possibly more efficient than original Perlin noise. I have tested this to work with 2- to 4-dimensions on Lazarus and Delphi. Uploaded to SVN version, also viewable here:
https://code.google.com/p/nxpascal/source/browse/trunk/src/nxNoise.pas
This is quick screenshot from 4D-animation, on TBitmap:
1176
Fill rate is roughly 1250 point calculations per 1 millisecond. So even this small 400x300 screen is slightly laggy. However if purpose is to generate a game world, this is quite alot, i guess.

Also uploaded demo zip with sources and win32 binary:
https://docs.google.com/file/d/0B7FII3MhcAHJSmxkc0pEVTNsTTg/edit?usp=sharing
All related nxPascal files are included there, so it will compile even without rest of the library.

hwnd
31-07-2013, 09:36 PM
Found a problem (actually a while ago) with nx.rs.AddBlend command.
On some machines it gives access violations when running examples.
Read of address 00000000.

I use my old laptop atm ( i have to) and it has: MOBILITY RADEON, AGP 16MB.

I also used addblend in my editor but i had to disable it for this to run on my laptop here.
The picking demo in nxPascal also has addblend and when i comment out nx.rs.AddBlend it works fine and no access violations.

So i guess the host machine must be checked if video card supports that and only then enable it.
Dunno, you decide. You can leave it as is also, if its possible for me to replace it with something then tell me also.

To be honest i dont even know exactly what it does.

User137
01-08-2013, 01:18 PM
There is possibility that the old card doesn't support GL_FUNC_ADD_EXT. I have currently no checks for card capabilities, but it is possible to use this:

if nx.GLInfo('GL_FUNC_ADD_EXT') then // Card supports it...
or nx.GetEXT to get list of all extensions in 1 string, for parsing many extension at the time.

But i made a little code reordering because it was quick. That extension is only used for SubBlend, but blending was general purpose function for both. Now this extension will not be used with just addblend at all, because it is not needed. (It is needed if addblend is going to be used after subblend.) Try new SVN version. I did quick test on existing blending demos, and everything seemed to be in order still.
(This doesn't make sub-blending work on those old, or should i say ancient, cards though. They are doomed to live without it ::) Unless custom fragment shader can be used...)

User137
11-08-2013, 06:49 PM
I have a new video to show you, of a new demo i'm adding to nxPascal:

http://www.youtube.com/watch?v=fS6Nb9UQBI8

It comes with 2 versions; 1 with normal drawing commands, and 1 with custom shaders. Normal demos are fully done for Lazarus and Delphi, and i'm only fighting with bugs on shader demo. Once they're dealt with and i finalize shader effects, i'll upload them all to SVN. In the meantime you can test the compiled win32 version of the demo
https://www.dropbox.com/s/wm275cn89k8q1go/Walkers_demo.zip
(Controls: hold left mousebutton and drag. F1 resets walkers.)

hwnd
11-08-2013, 07:34 PM
Runs fine but all i see is this:
I guess its the NPOT textures?
Because sparks are 32x32
http://i40.tinypic.com/157ghh2.jpg

My laptop again.

I think that nxPascal drawing functions should check if gfx car supports NPOT textures and if not, scale them to nearest POT with some default mode. Maybe with the best mode or smthng.

JC_
11-08-2013, 07:50 PM
Nice demo but i have this issue:

>600 wolkers and move with app window = permanent framerate lost (from 62-63 to 6-8 FPS)

User137
11-08-2013, 08:54 PM
Hmm.. it is fixed for both of you now i guess. Left texture files as NPOT but used tex.Options:=[toFitScale];
JC_'s notice was little different. It is not permanent framerate loss for me even if i moved window, but it piled up frametime to execute fast. I changed physics timing logic slightly and added new feature to game handler, SetMaxTick() which is now 100 by default. It depends on application i guess, if it's necessary to execute all lost ticks. But now it can be reverted with SetMaxTick(0) to ignore it.
edit: On my computer this version is drawing over 1500 walkers without slowdown at 60+ fps. They squeeze way out of the screen :D

SilverWarior
11-08-2013, 09:22 PM
On my Acer Aspire 6530g laptop I'm getting between 20-30 fps with about 1500 walkers.
Moving window does cause temporary framerate (longer the time I use for moving windows langer tha framerate drop).
I also noticed that you don't handle window resizing so whole sceene simply gets stretched which could lead to image distortion as the asect ratio isn't maintained.

hwnd
11-08-2013, 10:31 PM
Works fine now.
626 walkers, 26FPS.

Should be more on my PC, how is the collision made? Some intelligent stuff or just basic stuff?
They seem to avoid each other like peds in GTA_2. Although in GTA_2 they step back a bit if they collide with each other.
But your demo is almost same.

User137
11-08-2013, 11:34 PM
Yeah, nxPascal doesn't have real physics engine at the moment, so i made them "manually", using my little knowledge of physics. First lets take a look at the source code, as i finally got the shaders working and uploaded all to SVN. (I was sending array index to glUniform, when i should have sent index variable from that array's data... That's the point of using GLint type where header types are wanted, i just missed it.)

https://code.google.com/p/nxpascal/source/browse/trunk/demos/fpc/walker/GameUnit.pas#114
The program runs in single thread for simplicity. It gets vector that is from 1 walker position to other, and then pushes them both away from eachother by amount that is half of movement speed. Then sets function result true, meaning that collision happened. Main program will then check if there's time to count it again and runs the physics again and again until there are no collisions, or the 10ms that was allocated to each frame has elapsed.

I know i could've used syntax like:
position:=position+v;
... for vector math. But operator overloading is not Delphi 5-7 compatible, so i don't use them in the demos or engine internals.

edit: I added both versions, shader and non-shader to dropbox link (https://www.dropbox.com/s/wm275cn89k8q1go/Walkers_demo.zip) too. Shader version is unsurprisingly slower because of increasing amount of GL program changes as walker amount goes higher. The demo uses 6 different programs per frame, changing frequently.
(It doesn't mean shaders are bad, the opposite. They're just not meant to be changed that much ;) )

azrael11
12-08-2013, 07:47 AM
Runs great to me...
The Walkers_shader.exe demo with 1000 wallkers shows me 33 fps... in
An old Pentium 4 3Ghz with 1Gb ram...

Great good work...


Thank you...

hwnd
12-08-2013, 08:21 AM
Azrael, you call that old? I wish i had PC with such specs.

User137. Thanks, tried shader version, just throws me access violations at 00000000 constantly.
But nevermind, its a old laptop here and i will try how it runs on my home PC (which is not near me atm).
Home PC supported shader 2.0 if i remember correctly.

I will have to take some shader tutorial one day and start to experiment with them.

azrael11
12-08-2013, 06:26 PM
Azrael, you call that old? I wish i had PC with such specs.

Compare to the quad core Ivy Bridge with 16 gb rams and latest graphic cards....
I think is bit old...

But i like it...

Thank you...

SilverWarior
12-08-2013, 09:05 PM
Compare to the quad core Ivy Bridge with 16 gb rams and latest graphic cards....
I think is bit old...

Based on the fact that many games still doesn't support multithreading (most Indie games doesn't) having i5 or i7 processor doesn't guarantee you perfect performance in those games.
Infact I know of several games which actually, due to being single threaded, perform worse on some i5 and i7 processors than on some older Pentium4 or single cored Athlons.
Why is that? That is becouse the processing power of the single core of a multicored processor is sometimes lower than the processing power of some older singlecore processor.

hwnd
22-08-2013, 03:52 PM
What was the reason to not to add sphere-plane (plain, polygon) collision to nxPascal?

I want to use it for collision and ofc i have working C++ code that i will convert to Delphi, but anyway?

User137
22-08-2013, 08:14 PM
You can do sphere-plane collision with nxPascal. I'll explain the math using nxMath3D:


function RayPlaneIntersect(const rayOrigin, rayDirection,
planeOrigin, planeNormal: TVector; intersection: PVector): single;
First imagine that the sphere casts a ray directly towards the plane. rayDirection is inverse of planeNormal (or we could use equal too, it might not matter). If function result is >= 0, we get value stored in intersection vector. This means nearest point on the plane towards sphere's center.

Next we need to check if distance between intersection point and sphere is smaller than sphere radius. For that we could use Hypot3D(), but unless you plan to do something with the distance (such as manual physics), it may do more than you need. For simplicity's sake, you could place sphere back to where it was before collision. So instead of Hypot3D(), it will be faster to use PointInSphere():

function PointInSphere(const p,sphere: TVector; const radius: single): boolean;
PointInSphere is a truncated Hypot3D() without sqrt() call, and only tells if it collides or not.

Finally assuming that the sphere is moving in some direction, it will bounce off to other direction from the plane.

function Reflect(const rayStart, rayDir, wallPoint: TVector): TVector;
RayStart = Sphere current position.
RayDir = Sphere movement direction.
wallPoint = Plane intersection point calculated above.
Function gives as a result the new movement direction for sphere.

hwnd
22-08-2013, 09:12 PM
Ok and if i need to test / debug player sphere radius i just change the radius value for PointInSphere and thats same as changing player sphere radius? Im correct?

It tests for the sphere with specified radius. If i supply him radius 2, which is for ex. radius of the player sphere and this function will check that radius as if it was real sphere with that radius. I know im confuse things up but this is the way i understand it.

Anyways, thank you for the help. I will try.
But what about sliding / non sliding collision? I would like sliding more than sticking in wall.

User137
23-08-2013, 12:17 AM
I did sliding collision on the FPS demo.
https://code.google.com/p/nxpascal/source/browse/trunk/demos/fpc/fps/GameUnit.pas#151
The physics part in that is 11 lines long loop. It takes use of TGLModel.FindNearest() which scans nearest wall point of all nearest polygons, and then the loop pushes player away from it. It is similar logic as in the walker demo, only applied in 3D space. (*Similar*, not *same* because this version is much more optimal and accurate).


change the radius value for PointInSphere and thats same as changing player sphere radius? Im correct?
Yes that sounds same.

hwnd
23-08-2013, 06:12 PM
Sorry, forgot this FPS demo completely. Should have look it before.
Well, thats the coding / thinking in 4 AM when one should sleep.

Why 9(10) times loop?

Hmm, lots of good stuff there which i completely forgot. Bullets, weapon picking etc i could use.

User137
24-08-2013, 07:41 AM
Sometimes when you find nearest point and push player at its level, it can still be inside some other wall, especially when it comes to corners. Normally it finishes the loop on 1 or 2 rounds at max (maybe 4 times in worst case, of hitting cubic room bottom or top corner), but it just does the collision work looped, so that it doesn't have to do that on next frame. It makes the collision look much smoother.

hwnd
06-09-2013, 08:32 PM
I just executed the shader demo (GLSL test) on my pc and it works fine, but whats important is that CPU usage is 0 or between 1-2% if you move mouse a bit over the window.

So im wondering, is it possible for me to still make the map editor to use timer (DxTimer, threadedtimer) with "onidle" with interval 16-17ms or something but still somehow run it on same speed on every pc if i do for example camera movement, rotation, animation?

Like i said in old messages, before even discovering the nxpascal i used timer with interval 1, because i used some akward picking code that got too slow when timer interval was like 16-20, in tile painting mode the tiles appeared with big delay.
How the ray picking is affected on timer interval?

I dont know even if i said that correctly. Im not good with english.

Can i do same without actually using that game loop? Which eats CPU always, even if i dont do anything in editor.

I really would like CPU usage 0 rather than 20-30, i really dont like that. Tried to setframeinterval() to different values, still CPU usage is too high.

I really like how original editor sits on 0 always, until you do something (it can get really high) but when just nothing is done, it sits at 0. No lag or anything on other apps.

EDIT: also why you init stuff in OnPaint? Why not somewhere else (in own Init function, FormCreate or something) ? Any particular reason?

SilverWarior
06-09-2013, 09:27 PM
EDIT: also why you init stuff in OnPaint? Why not somewhere else (in own Init function, FormCreate or something) ? Any particular reason?

Not sure for that example but I saw that many graphical engines contain necessary code for initialization in OnPaint routine.
In most cases this code is there to alow recovering from display device handle loss (switching between internal and dedicated GPU, VPU recover which might be caused by some error in shaders or due to hardware problems, etc.).

hwnd
06-09-2013, 11:08 PM
Ok, good point.

Now i have found my old editor sources which use glLoadName methods for picking and TTimer with interval of 2ms for drawing map. I have 0 CPU most of the time, and goes up to 20-60 maybe when drawing something or rotating or something else.
Of course 1-2 is too quick and standard ttimer cant even handle that properly but if i will use threadedtimer with interval 16-17 for example, dunno if that will make ray picking slower? I guess not.

Again, why i have timer with 2ms (ie. drawing map each 2ms) its because of the picking method i use and because of the "tile painting" in my editor. User can "paint" tiles on terrain. If i set timer to 20-30ms then this picking and drawing gets very slow. The painted tiles will appear with very big delay on terrain and may even not appear at all. Because if user moves mouse too fast then it cant even catch all these coordinates so quickly because low timer interval.

This is how i did things before (~2007-~2011) i found nxPascal.

Im talking about the old editor from my backups.
The current one uses game loop but eats cpu always, even if its minimized or not active at all.

Dunno how it would be with TTimer or threadedtimer with interval of 30ms and ray picking from nxPascal.
I have to test.

SilverWarior
07-09-2013, 06:49 AM
You should split the drawing code and picking code into two sections.
Drawing code gets executed every 16-17 ms. No need to execute it more often as your monitor is probably not able to render more frames per second which means that anything beyond that is just waste of computational power.
But picking code gets executed more often to alow smoth pickings.

I disadvise you from using standard TTimer as it relies on Windows messages. This means it has great of achieveing smal tme intervals (lers than 5 ms) and it would probably have ocasional problems even when dealing with higher time intervals (ocasional delays which could reach even to 1s).

hwnd
07-09-2013, 09:12 AM
I just typed long text into here on my Android phone and it just restarted for unknown reason. I hate that.
Ok starting over.

I will use ThreadedTimer or similar. Atm i have Draw function which has the ray picking code at the beginning, actual drawing code in the middle and SwapBuffers at the end.

But how i could split them? Use another timer for picking and set its interval to something like 5-6ms?
While main drawing timer will be 16-17ms?

I will have to try. It would be really nice to have rendering code use 0 cpu most of the time and at the same time picking to be smooth.

Btw, yesterday i quickly copy pasted together small test opengl app with raypicking and thdtimer, rendering was 0% and when i moved mouse around and did a ray picking very often (timer interval) cpu usage didnt even go up.
Seems that ray picking is so fast.
There is also small optimization, before even checking triangles it checks if ray even collided with bounding sphere of the object, if not it will not even check the object.

While with Opengl name stack it goes up significantly.

hwnd
07-09-2013, 09:53 AM
Ok, i tried with thdtimer and Application.OnIdle := Idle;
It works in both. Speed seems fine but i dont understand why the picking has offset to the left when at the right i must move mouse cursor almost to the center of the tile for it to disappear. Down seems also bad. Especially when moving mouse slowly i can see how it almost goes to the center of the tile and then tile disappears.

When i move to the left, tile disappears even without touching it. Very big offset. same with UP.

Strange. I have to drink some coffee, maybe im sleepy. Just woke up.

User137
07-09-2013, 10:57 AM
You can use onMouseMove event on form for the tile-painting, then it doesn't matter if you are using 16+ interval. Actually that could be the reason for high cpu use in the first place. Game template-based programs run same speed on all machines, but it's important that you put game mechanics into GameLoop, and rendering into Rendering procedure. If you would mix game mechanics with rendering code, frameskipping could mess up the sync.

Also keep in mind that you have another thread specifically for the GTA editor, this is about the engine alone.

hwnd
28-10-2013, 08:33 AM
Any particular reason why you removed "boundsf" and "boundsi". Or they just were duplicates of something?

User137
29-10-2013, 06:13 PM
They are in nxTypes as far as i see
https://code.google.com/p/nxpascal/source/browse/trunk/src/nxTypes.pas
I don't remember where i moved them from, but it seemed more proper place.

Chesso
30-01-2014, 11:36 PM
Hi,

Was looking into trying this, got all the paths etc setup but can't compile the FPS demo into Delphi XE2, by the looks of it due to the old pngimage library (lots of left side cannot be assigned errors).

I think XE2 has PNG built in suppose I might have to play around with it!

Oh before I forget, I wanted to use this to dabble around with 3D (never really tried it before), does nxPascal load/manipulate models of a particular format?

hwnd
31-01-2014, 12:54 AM
You should enable Assignable typed constants in compiler options.
Set to True.
But yes, XE2 should have already png support, just remove the nxPascal png folder from the paths.
If i remember correctly, i had same problem with XE(2)
http://img.my.csdn.net/uploads/201104/28/0_1303976998Mlia.gif

Chesso
01-02-2014, 06:29 AM
You should enable Assignable typed constants in compiler options.
Set to True.
But yes, XE2 should have already png support, just remove the nxPascal png folder from the paths.
If i remember correctly, i had same problem with XE(2)
http://img.my.csdn.net/uploads/201104/28/0_1303976998Mlia.gif

That didn't make a difference for the left side cannot be assigned too, I assume it's a recent update in XE series. I never had to deal with it because I never did it that way lol.

I remove png though and managed to get it to compile, had to remove BASS audio references too (so no sound) due to errors but I know how to use BASS directly anyway.

Does anyone know what, if any 3D model formats are supported?

User137
01-02-2014, 10:31 AM
Supported formats are W3D (used in my Edit3D modelling program that comes with nxPascal), OBJ and MilkShape3D ascii format. None of them support joints or animations at the moment, and i am not 100% sure that OBJ and MS3D are bugfree.

Also you could definitely tell me, maybe in private messages more details about these compile errors. Again i was not aware at all that there was a system where nxPascal would not work straight out of the box. I am still mainly supporting Lazarus only, and i don't have any Delphi installed on my computer.

Chesso
01-02-2014, 10:47 AM
So I would assume 3D wise pretty much anything goes aside from animation (anything requiring joints etc) and probably high poly count stuff (don't know a lot about 3D).

The only problems so far with demo's are with the included pngimage which is solved by removing that folder, PNG is support directly in Delphi for some time now (I think it's even the same guy that implemented it), and with
the BASS implementation (the included .pas) file had quite a few errors but I just removed sound from the game so I could test it rather than mess about with it.

I have always used Delphi as I like the IDE although I don't use a lot of it's features, never tried Lazarus or others.

User137
01-02-2014, 12:01 PM
These different compiler related issues are often solved with IFDEF's. If you see here:
https://code.google.com/p/nxpascal/source/browse/trunk/src/nxInc.inc
there is for now only definitions for which compilers support inlining (by removing function and parameter overhead it can increase math functions performance great deal, at slightly higher memory cost). There could also be a {$DEFINE OldPng} that would only be active on older Delphi compiler versions. But again, as i don't have a Delphi it is difficult to do something like that on my own. Do the png's work then with no reference unit in uses list? I don't know where the new Delphi finds the needed PNG class, and since what version it was available.

bass.pas or nxBass.pas? If it's bass.pas, then it should be reported to them, possibly with suggests on how to fix them.

SilverWarior
01-02-2014, 09:08 PM
In Delphi PNG images are supported trough TPngImage class which is a subclass of TGraphic and is located in "Vcl.Imaging.pngimage" unit.
But based on Lifepower there is/was and isue with Delphi built-in PNG support regarding alpha channels so Lifepower sugested to use "Vampyre Imaging Library" with Asphyre Sphinx 3 instead of Delphi built-in PNG support.

Delphi's PNG implementation has an issue in alpha-channel. An alternative solution is to use Vampyre Imaging Library and add AsphyreVampyre to USES list. This solution also works for FreePascal/Lazarus. You should download the latest snapshot from the link below.
This was at the time when Delphi XE2 was out so it is posible that the problem was already fixed by now (I haven't tested it out).

As for BASS Audio Library:
I don't exactly remember when but in one of the previous versions there were some serious changes made which means that it is no longer posible to simply compile old program with newest bass.pas unit.
Not sure what changes were made but one project of mine throws almost a hundred syntax errors. All demos that come with BASS library compile just OK. And yes I tried this on Delphi XE3 and Delphi 7 with which I have developed my project in the first place. So one day I'll have to take tme and see what changes were made and update my code acordingly.

paul_nicholls
02-02-2014, 02:00 AM
Regarding PNG units...I prefer to use Be Ro (Benjamin)'s free cross-platform PNG unit:
http://www.pascalgamedevelopment.com/showthread.php?9861-BeRoPNG-A-very-tiny-but-complete-PNG-loader&p=97221

See one of the last posts for a pure Pascal version (compatible with Freepascal, Delphi XE3 & XE4):
http://www.pascalgamedevelopment.com/showthread.php?9861-BeRoPNG-A-very-tiny-but-complete-PNG-loader&p=94019&viewfull=1#post94019

cheers,
Paul

hwnd
28-04-2015, 04:05 PM
I was at work, had nothing to do and thinked about modern OpenGL 3.x and nxPascal.
Its pretty difficult to setup matrices, vertex data etc with modern OpenGL and the shaders needed for matrix stuff and so on.
So idea for the nxPascal.

Make everything "behind the scene" and let user to use simple to understand and use commands.
For example lets take: glTranslatef(), nice command to "move things" and position them in place.

In modern gl you have to do alot of dirty work to implement this. At least i see it so and its just one (!) example.
So make everything needed in modern OpenGL to get the same result. But instead calling it again glTranslatef, call it for example: nxTranslatef or something.
So i build my mesh and want to position or move it i just use for ex: nxTranslatef(2.0, 2.0, 5.0); (XYZ) order.

And same for other things.
There could be some shader templates provided for matrix stuff, for cameras etc.

With such commands and nxPascal doing all the "hard" things behind the scenes will make using modern OpenGL much easier.


What do you guys think?


I would like to rewrite my map editor for new OpenGL 3.x+ but the amount of writing code just for building mesh and simple camera matrix stuff scares me.
I dont even know proper good OpenGL headers for new OpenGL versions, except dglOpenGL. Is it even updated lately?

Share your thoughts.

SilverWarior
29-04-2015, 02:52 PM
So basically you are thinking about adding aditional abstract level which will hide most low level fidling nad thus make your engine more user friendly. I think that is a verry good idea.

But if you do decide to do this then I recomend you give it a more deeper thought and try making it in a way that it would not only alow you to hide some low level fidling but also open you a way to implement other types of renderning like DirectX support etc.

User137
13-05-2015, 06:01 PM
Camera class was already implemented, as far as i'd understand what you mean. See in picking demo:
https://code.google.com/p/nxpascal/source/browse/trunk/demos/fpc/picking/GraphicsUnit.pas#82

There hasn't been motivation to pascal coding for propably over a year now. It's difficult to make myself come back to this, with Unity and stuff around :( In the end i will never be able to compete with features, code quality, portability and simplicity.

I have also started the project moving into github, since code.google.com is quitting.

edit: Moving is completed, and wiki converted.

Chesso
27-06-2015, 08:17 AM
Camera class was already implemented, as far as i'd understand what you mean. See in picking demo:
https://code.google.com/p/nxpascal/source/browse/trunk/demos/fpc/picking/GraphicsUnit.pas#82

There hasn't been motivation to pascal coding for propably over a year now. It's difficult to make myself come back to this, with Unity and stuff around :( In the end i will never be able to compete with features, code quality, portability and simplicity.

I have also started the project moving into github, since code.google.com is quitting.

edit: Moving is completed, and wiki converted.

It would be great if you continued the project, iv'e played around with unity and stuff but I like programming pascal lol.

Roland Chastain
27-06-2015, 05:26 PM
Yes, it's a very nice library. The demos are awesome! Unfortunately I never found time to make something with it, but I still keep it in my Lazarus directory. :)

User137
29-01-2017, 10:19 AM
I released a few fixes to github after a long period of silence.
- BASS supports now both 32 and 64-bit compiling. Executable location or windows\system32\ needs to have either bass.dll or bass64.dll. If it can't find the dll you might get no error at all. App just won't start. It's not a bug i can fix. Of course if nxBass is not included in project, this note is irrelevant.
- Changed many demos project options to "default" compiling settings. A few had them set to 32-bit which then failed to compile on 64-bit.
- Using Enable2D and then resizing window without first calling Disable2D no longer blacks out the screen.
- FileExistsUTF support dropped in favor of new fpc compiler. It became deprecated.

Added a few known issues to the issue tracker https://github.com/Zaflis/nxpascal/issues and i'll try to keep it updated even if i didn't have time to fix them (i still might sometimes). I'm now developing on Windows 10 using 64-bit Lazarus and FPC. No virtual machines at the moment, and even if i did they might have trouble running with hardware acceleration. So i can't test on Linux. And i have no Delphi at all, considering dropping its support altogether. Is anyone using this on Delphi?

Thyandyr
18-05-2017, 07:22 PM
Not exactly using it, but from all the engines I've tried it was the easiest to get to work in Berlin 10.1 VCL

I haven't made up my mind about what to pick for my project, but this is one of the top candidates.

turrican
05-06-2017, 11:03 AM
I test it and works awesome! Android support would be great :)