G2D - 2D OpenGL library for PlayBASIC (WIP / BLOG / SCRATCH PAD)

Started by kevin, June 24, 2014, 02:08:07 PM

Previous topic - Next topic

kevin


  G2D - Prototype # 16 - Particles Updates

    Since the camera has been updated added a function to draw particles into a camera scene, rather than the screen.   Have added some future controls to the particle render to control individual particle colours as well as the intensity allowing them to in/fade out when drawn alpha addition.   It still doesn't support frames though.. 

   anyway, here's a version of the xenon perspective scene with a  bunch of spawns in the world


kevin

G2D - Can you run Wolf3D demos in Opengl ?

  Yes and no...

  I tried the latest build of the prototype, but it's missing UV controls for the TextureTRI and TextureQUAD commands. These are essential for subdividing not just floors and walls, but also objects.

So, off I go digging through old backups trying to find the G2D source code from 10 years ago. After a bit of hunting, I found what claims to be revision #15—good enough for now! All I really need to do is add UV support to those functions. They won't render in the correct order on screen yet, but at least it should give a sense of what's possible.

How do we build this? 
Good question. I fired up PlayBASIC V1.64P4, since G2D was written in PlayBASIC and built into machine code using PlayBASIC2DLL (for PB V1.64P revisions). The project is half demo, half library—and mostly a mess around, to be honest. But yep, I eventually tracked down what I believe is revision #15 of the source.

Skimming through the code, I found the original TextureTri and TextureQuad implementations. Instead of replacing them, I renamed them to G2dTextureTri2 and G2dTextureQuad2 and made those the base for the updates.

 Adding the new functions was one thing, but how do I turn this into a DLL? 
Well, I had written a PlayBASIC project loader ages ago that does a bit of preprocessing to generate the DLL. This was all covered in a blog post somewhere that no one read, of course...

 Basically, it loads the project and all its includes into one giant blob, scans through the code, and strips out anything tagged with `[removedme]` comments. That's needed because the project's built from various sub-libraries. (Smaller projects don't usually need this.)

  Once the builder was working, I just fired up PlayBASIC2DLL and compiled the merged source (`merged-source.pba`). The tool runs PB to compile and optimize the code in PlayBASIC space, which is then converted to assembly and passed off to the assembler. Boom—seconds later, we've got a DLL and a library of public function names.

 So now what? How does this hook into the WOLF3D demo?
Just include the library, call `G2dSTART()` to kick things off, and replace the old DX-style drawing commands with G2D equivalents. So, `TriC` becomes `G2dTriC`, `TextureTri` becomes `G2dTextureTri`, and so on.

 Then you hit run and hope! And—surprise, surprise—it actually works. Sort of.

 There are rendering issues though. Since we're drawing polygons out of order and expecting the PlayBASIC camera to sort everything from back to front, things get drawn incorrectly. Also, the wall perspective looks off because I'm only subdividing columns, not the full surface.

  But hey, you get that.

 

  Related Links:

      - PlayBASIC Project Loader + Source Code Merger

      - PlayBASIC To DLL Blog

      - Yet Another Wolfenstein 3D Demo (Texture Mapped Floors & Ceiling)
 

      - Download G2D Library (login required)


kevin


Wolf 3D Ported G2D Library Tech Demo

   This is variant of the Wolf 3D affine texture mapping demo that's been ported to the use the G2d library for PlayBASIC V1.64 editions.   G2d was an open gl  prototype written in conjunction with PlayBASIC2DLL (a conversion tool for converting PlayBASIC code to machine code dll's) 

   The library provides a list of basic primitives and some emulations of the built in features from sprites / fonts / maps..  To get this code working has working this well has meant updating the legacy g2d library and updating the wolf 3d code..  These fix the perspective, but there's no z sorting of the faces in this build.  Which is required since this is 2D rendering using affine texture mapped polygons.  The faces are subdivided to hold perspective in the scene.