Page 12 of 18 FirstFirst ... 21011121314 ... LastLast
Results 111 to 120 of 179

Thread: nxPascal

  1. #111
    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.

  2. #112
    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.
    fps_demo.jpg
    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.
    Last edited by User137; 01-03-2013 at 08:13 AM.

  3. #113
    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:
    Code:
    #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:
    Code:
    #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);
    }
    Code:
      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 Attribs, ambient, diffuse, matrix calculation is all working. Can soon start finishing 3D shader aswell.
    Last edited by User137; 03-04-2013 at 02:42 PM. Reason: small fixes..

  4. #114
    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:
    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.
    Attached Images Attached Images
    Last edited by User137; 08-04-2013 at 09:37 AM.

  5. #115
    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.

  6. #116
    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.

  7. #117
    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!

  8. #118
    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.
    Last edited by hwnd; 13-04-2013 at 09:59 PM.

  9. #119
    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.

  10. #120
    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
    Last edited by rferriz; 19-04-2013 at 03:32 PM.

Page 12 of 18 FirstFirst ... 21011121314 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •