Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

simple 3d rasterizer made in sdl2

NotificationsYou must be signed in to change notification settings

BjorneEk/3d-graphics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


A program that reads obj files and renders them in a window.

The goal with the project was to render aUtah-teapot in a window using only code written myself. I was mostly successful in doing this however i had to do some research and learn about projection matrices as well as freshen up on cross products.


The program is fairly limited in the files it can parse and it will not be able to render all .obj files. For a file to function it cannot contain normal data and the faces must be triangles. see the example below for a simple cube.

This file works:

o Cubev 0.0 0.0 0.0v 0.0 0.0 1.0v 0.0 1.0 0.0v 0.0 1.0 1.0v 1.0 0.0 0.0v 1.0 0.0 1.0v 1.0 1.0 0.0v 1.0 1.0 1.0f 1 3 5f 3 7 5f 5 7 6f 7 8 6f 6 8 2f 8 4 2f 2 4 1f 4 3 1f 3 4 8f 8 7 3f 2 1 5f 5 6 2

This file does not:

o Cubev 0.0 0.0 0.0v 0.0 0.0 1.0v 0.0 1.0 0.0v 0.0 1.0 1.0v 1.0 0.0 0.0v 1.0 0.0 1.0v 1.0 1.0 0.0v 1.0 1.0 1.0f 1 3 5 7f 5 7 6 8f 6 8 2 4f 2 4 1 3f 3 4 8 7f 2 1 5 6

The lines begining with a 'f' in a .obj file represents a face and they have to be in the formatf P1 P2 P3 and notf P1 P2 P3 ... Pn orf P1/N1 P2/N2 P3/N3.


Usage

$ ./3D-graphics <filename.obj>$ ./3D-graphics <filename.obj> rand (for random colors)$ ./3D-graphics <filename.obj> <FOREGROUND_COLOR> (RED, GREEN, BLUE)$ ./3D-graphics <filename.obj> <FOREGROUND_COLOR> <BACKGROUND_COLOR>$ ./3D-graphics <filename.obj> <FOREGROUND_RGB> (1,0.7,0.3) values between 1 and 0$ ./3D-graphics <filename.obj> <FOREGROUND_RGB> <BACKGROUND_RGB>

controlls

KeyAction, enable/dissable
Hwireframe
Jrender with color
Lrender with light
kdissable triangle sorting
W/UPmove light source up
A/LEFTmove light source left
S/DOWNmove light source down
D/RIGHTmove light source right
left mouserotate object
SHIFT+ left mousemove object
scroll wheelmove object in Z dir

lang

size

lines

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp