Sign in to follow this  

Need some answers for software rendering

This topic is 673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 )

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Edited by FRex

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites


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.

 

you'll want an offscreen buffer to render to, then copy the final results to SDL.

 

i wrote a software renderer once for SIMTrek.

Share this post


Link to post
Share on other sites

This topic is 673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this