This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jv110's profile picture

VertexGL - 3D rendering API with polygons, textures (!) and shaders

Started by jv110, 24 February 2016 - 12:54 AM
jv110 #1
Posted 24 February 2016 - 01:54 AM
This is a very simple 3D graphics library, nothing too impressive, but still worth sharing.

You render in it by just clearing the screen, providing a vertexarray to your vertexgl object and specifying UV coordinates (!) if you want.

There are also vertex and fragment shaders which are functions executed on each vertex received and each pixel drawed (respectively), used to alter the vertex position (For cameras and such) and pixel color (For anything really).

The (!)s are because textures aren't working as I don't have any UV coordinate calculation algorithm. I've searched a lot and couldn't find a working one, and I came up with one some time ago but i didn't save it so it's gone.

The file also includes vec3, vec4, quaternion, mat4x4 and vertexarray.

Current functions:
Spoilerviewport(width, height)
Sets the size of the screen to render to.

ortho(left, right, bottom, top, near, far)
Sets up an orthographic projection matrix (applied automatically).

perspective(fov, ratio, near, far)
Sets up a perspective projection matrix (applied automatically). Ratio should be 1 for stretched rendering and width / height for perfect pixels.

clear(color (optional))
Clear the rendering buffer. If the color is not specified, it will default to black.

draw(vertexarray)
Draws the specified vertexarray object to screen.

genTexture(width, height, pixels)
Returns a texture object with the specified properties.

bindTexture(texture)
Makes all subsequent texture operations be on the specified texture.

unbindTexture()
Same as bindTexture(nil). Binds a nil texture.

The GitHub repository for it includes VertexGL itself and a test program which loads that classic Blender monkey from an .obj file and draws it:
https://github.com/jv110/VertexGL
Edited on 24 February 2016 - 01:05 AM
Creator #2
Posted 24 February 2016 - 06:05 AM
This s seriously is awesome. I have worked on something similar and have never gotten past the point where I render a wireframe cube.
Would you mind sharing some screenshots?
jv110 #3
Posted 24 February 2016 - 09:58 AM
I can't share screenshots right now, but here's one from the monkey thing I posted on Twitter:
http://i.imgur.com/JGrWpRG.png

I don't knoow why, but it doesn't look so good, render anything else and it will look like the best thing ever
Creator #4
Posted 24 February 2016 - 02:38 PM
That looks amazing! How good are you with Blender?
jv110 #5
Posted 24 February 2016 - 03:41 PM
Not so good, but I can get some pretty good results if I spend some time.
Edited on 24 February 2016 - 02:44 PM