Need some answers for software rendering

Started by
9 comments, last by Norman Barrows 8 years, 2 months ago

hi I'm using sdl library for 3d rendering but I had a problem that it had only two drawing method like a pixel and a a line.

so I didn't controll all of pixels from meshes with z depth. how can I do drawing meshes with z depth and alpha blending? I reall don't know it. wacko.png

( I know the works : draw 3d objext to viewport plane with clipping area -> transformation. but I don't know : z buffering with sdl drawing functions -> alpha blending )

Advertisement

Is there a reason you want to do this without OpenGL (which SDL supports)?

Software 3D rendering went out of fashion a long time ago...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

@swiftcoder

I want to learn more about 3d software rendering only with my funny cool.png

Well, for software rendering, all you have to be able to draw is pixels. Everything else (lines, triangles, ... alpha-blended depth-sorted polygons) are just made up of pixels.

Of course, since it's software rendering, you are going to need to implement all the functionality that you mentioned for yourself: line and triangle rasterisation, depth buffers, alpha blending.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

There really is no magic, all you need is some math (matrices mostly) and nice quick code here and there...

Here are two very good reads about software 3D to get the brain going:

http://fabiensanglard.net/quake2/quake2_software_renderer.php

http://nothings.org/gamedev/thief_rendering.html

And here's my own 3D rasterizer. It's messy, inefficient and has weird model format and lots of hardcoded stuff. It was a homework. I use armadillo for matrices operations.

I'd not call myself at all experienced in 3D (or even 2D) graphics, but I know how to do C and C++ and the basic principles of 3D graphics so I wrote it with relative ease.

https://github.com/FRex/brender

It has just the basic triangle raster (done by iterating trough aabb and checking the barycentric coords, scanline would be better and faster but harder to code) with color interpolation and texture mapping (perspective correct one.. I think.. I don't remember now), some crappy shading (I don't remember which kind of shading and it was a little rushed too) and Z buffer and winding based culling.

It has no alpha, but alpha is no magic either, you just need to define the formula (or few) for computing the resulting pixel color based on alpha and destination current color instead of just overwriting it with the new one.

Of course then you get the usual issues of drawing back to front and so on, like in real 3D.

And I'd advise against doing it, just use a 3D API instead unless you want to learn for the sake of knowing.

If you really want a trial by fire, look at the quake 2 software rasteriser or the quake 1 source.

These are early examples of 3d done completely in software with texturing and lighting but they take some really clever and complex shortcuts which will make you go "o_O".

Have fun!

Some more links for you :). http://www.gamedevpensieve.com/graphics/graphic-api/software

@spinningcubes | Blog: Spinningcubes.com | Gamedev notes: GameDev Pensieve | Spinningcubes on Youtube

@swiftcoder

yep definitely I know I must code all of drawing functions smile.png

@FRex , Braindigitalis

I know how to fill mesh with interpolation or textures and z buffering

but I really don't know how to access sdl's screen pixel buffer because sdl only support drawing pixels , lines and filling a rect.sleep.png

I can make a drawing line functions with filling mesh if I know how to access sdl buffer.

( I don't code it through assembly etc )

@Spinningcubes

Thanks it'll help me to do some works later biggrin.png

https://wiki.libsdl.org/SDL_GetWindowSurface

https://wiki.libsdl.org/SDL_Surface

check out the functions SDL_LockSurface and SDL_UnlockSurface

@Crossbones

Wow thanks~!~rolleyes.gif

This topic is closed to new replies.

Advertisement