3D Rendering without openGL or other libraries

I wanted to make my work on a 3D rendering engine available for somebody who might find it useful . The whole thing is one header file : you enter screen height, width , angle of sight , direction of sight and position of the eye and the coordinates of a 3D point and you get the x,y coordinates of that point on the screen, as simple as it can get. What that gives you is the capability of making vector structures easily . The comments on the code are in english and bulgarian (I haven't interpreted them all) . If you have any questions (as in you want to know how it works , because it'll be hard to get from the code) or remarks I'd be happy to address them :) . The code turned out a bit too long to post here . Here's a link to SourceForge : http://sourceforge.net/projects/renderh/files/Render.h/download

Last edited on
I'll be harsh: the design you've chosen makes this completely useless.
To avoid overdrawing, one would want to do exactly the opposite of you're doing. Start from a screen coordinate and see what's visible from there. If you start from a scene coordinate, it means that to, for example, draw a line, you'll have to sample points in that line and hope that the resolution is just right. If it's too high, you'll draw far more points than necessary; if it's too low, the line will look like just a bunch of points.
http://imageshack.us/photo/my-images/181/perspectiveaf7.png/
That's why I mentioned vector graphics - If you want to draw lines (say a cube) and observe them from different points of view you'll do the following :

#include <Render.h>

int main (){
// for a cube with apexes on the points A,B,C,D,A1,B1,C1,D1

lense L;
Dot A,B,C,D,A1,B1,C1,D1;
float x,y,x1,y1; //rendered points

L.x=0; //eye initial position
L.y=0;
L.z=-100;

L.h=0; //eye initial direction
L.v=0;
L.r=0;

L.s1=45; //parameters
L.s2=45;
L.Scr1=960;
L.Scr2=960;

A.x =0;
A.y=0;
A.z=0;

B... //setting up the cube
...
...

...
...
D1.z=10;

while(!window_closed){

if(key_pressed){

//here's the routine to change the eye position via the keyboard/mouse
//for example :

switch(key_pressed){

case 'D':
L.x+=10;
break;
case 'A':
L.x-=10;
break;

case 'W':
L.y+=10;
break;

case 'S':
L.y-=10;
break;
} //end switch
} //end if

//Rendering :

Render(L,A,x,y);
Render(L,B,x1,y1);

draw_line(x,y,x1,y1);

Render ...
...
...
//or do some kind of loop or something to do as much lines as you like

// to be legit here I should put a flip_buffers(display); or a clearscreen in the beginning or something , depends on what you're using to draw with

} //wend

return 0;
} //end main

I may have missed something but that's just a basic example for the lines . If you wanted to draw spheres it would be like :

Render(L,A,x,y);
r=g1(L,A,SizeOfA); //sizeOfA being the real size (radius) of the sphere with center A , and r - the image radius

Draw_circle(x,y,r,color); ...
Last edited on
Topic archived. No new replies allowed.