Blog about (Web-) Programming, Graphics and Games.

11.03.2010

Towards a Web-RTS-Game

Here is a demo for a real-time-strategy (RTS) game using WebGL. Currently there is only very basic gameplay: you can select units using left mouse button and let them move around with the right mouse button. Following is planned for future releases:
  • Map and gameplay enhancements. Add strategy to the real-time
  • Use of other html5 techniques, e.g. audio-tag for audio, websockets for multiplayer gameplay
  • Custom content creation and modification. Users will be able to upload own units and maps to a central repository. Also AI of units might be controlled by editable user-scripts...

Kommentare:

Anonym hat gesagt…

Nice demo!
However, very much performance is lost in some very inefficient calculations, especially calcVerts.
Mmul is also quite slow. See ewgl (http://code.google.com/p/ewgl-matrices/source/browse/trunk/ewgl-matrices/javascript/EWGL_math.js#167)for fast matrix and vertex implementations. Also use WebGLFloatArrays as much as possible!

Good luck!

pl4n3 hat gesagt…

Thanks for the comments and link. That will help me to make the code more efficient. Are there nice tools to detect performance-bottlenecks in javascript-code? I too have in mind to implement more stuff using WebGLFloatArray, maybe also the inner matrix representation.

Anonym hat gesagt…

Yes!
In Chromium and Safari you have a built-in profiler (Chromium: Page icon, Developer, Developer Tools, Profiling) and in Firefox you could install Firebug.

pl4n3 hat gesagt…

Nice! I will take a look at that.

James Gregory hat gesagt…

I get an error, maybe my graphics card is not good enough? (Radeon HD 3650). Though gnomwgl.htm works fine.

Error message:

http://www.jameswritesstuff.co.uk/err.png

pl4n3 hat gesagt…

Thanks for the comment and error message. Here I cannot reproduce the error (I have nvdidia gtx 8800). With regard to gnomwgl.htm, I changed the shaders (to introduce transparency for shadows and cursor). This might cause the crash on some computers..

James Gregory hat gesagt…

I guess it is probably just the card, it is pretty old.

pl4n3 hat gesagt…

Yes, that may be the case. Btw, the demo runs on my computer with minefield and with chromium (http://bit.ly/9G5Z01) but not with chrome dev.

Anonym hat gesagt…

same error message. running current mozilla firefox nightly build and current chrome "dev channel".

In Firefox (Minefield 3.7a4pre) no content is rendered in the canvas. In Chrome (5.0.360.4) the models are loaded once accepted the error message, but instead of textures, they look white and un-playable.

Maybe this link helps you in the debugging, so i'll paste it here: http://khronos.org/webgl/wiki/Debugging

Anonym hat gesagt…

I can also confirm that the behavior in chromium 5.0.366.0 (43120) is very similar to Chrome: Shader fails to compile, so you get untextured actors.

If it worked 19 days ago, then maybe something has changed in the spec.

pl4n3 hat gesagt…

I cannot reproduce the bug, here it runs with chromium and minefield. It probably depends on graficcard. Maybe someone can tweak the shaders so that they dont cause that error and post the results here. That would be nice.

Anonym hat gesagt…

I get the same error compiling the shader with http://www.iquilezles.org/apps/shadertoy/ . I wish I could be of more help, but I'm not a GLSL expert.

For the record: The spec changed last week and latest builds are adapted to it. WebGLArray has changed, getParameter and getAttribLocation have been merged, getContext has been corrected and in general, a lot of previous WebGL work is now incompatible with the spec and doesn't work with latest builds. All examples in http://learningwebgl.com/blog/?p=11#examples do work with my GFX card.
However, I don't think that is the issue. I don't think Shaders have changed. ATI card here. It runs a dx9c shader model 4 game daily.

Anonym hat gesagt…

OK, I got the shader fixed. Where it says "uniform float uAlpha=1;" , it must read "uniform float uAlpha=1.0;". woot, now I can write GLSL!

pl4n3 hat gesagt…

Thanks for the help! I updated the source with that fix.

santa hat gesagt…

This fails in WebKit nightly with WebGL enabled, with the error:

ERROR: 0:3: 'uniform' : cannot initialize this type of qualifier

This like this is due to this line:

uniform float uAlpha=1.0;

Initialization of uniforms is not allowed in GLSL, but apparently some drivers allow it.

Chris Marrin hat gesagt…

This fails in WebKit nightly with WebGL enabled, with the error:

ERROR: 0:3: 'uniform' : cannot initialize this type of qualifier

This like this is due to this line:

uniform float uAlpha=1.0;

Initialization of uniforms is not allowed in GLSL, but apparently some drivers allow it.

pl4n3 hat gesagt…

Sorry for long time no update, but the Webkit issues should be fixed now.