-
Notifications
You must be signed in to change notification settings - Fork 1
/
readme.txt
290 lines (181 loc) · 9.19 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
[ Introduction ]
PixelToaster is a library for C++ programmers who want to write their own
software rendering routines, instead of using hardware accelerated
rendering with OpenGL or Direct3D.
To use PixelToaster, all you need to do is "open" a display at the desired
resolution, then each frame, render into an array of pixels and "update"
your pixels to the display.
[ Installation ]
* Windows:
PixelToaster for Windows requires DirectX 9.0.
First you must make sure you have the latest DirectX Runtime installed.
Visual C++ Users:
- Install the latest DirectX SDK so you have its headers and libs
- If you are using Visual C++ Express, you need to install the
Platform SDK if you havent already. Follow the instructions on
the Visual C++ Express site.
- If you plan on building PixelToaster from the command line (nmake)
make sure you add the appropriate DirectX directories to your LIB
and INCLUDE environment variables
- To use the solution file, just open PixelToaster.sln select the
example project you want to build (right click, make active project),
and press F5 to build & run. For speed, switch to "Release"
- The solution file only supports the latest Visual Studio 2005,
so if you have an earlier version of Visual C++, you'll need to use
nmake or create your own solution/project files.
- To use nmake, open "Visual Studio XXXX Command Prompt" to get a cmd
line with the path and environment fully setup, then type:
nmake -f makefile.visualc
MinGW Users:
- You *DO NOT* need to install the DirectX SDK
- Make sure your MinGW installation includes the Windows and DirectX
headers. The easiest way to do this is to simply install the entire
MinGW package instead of the smaller pieces. The full package
contains everything you need to build PixelToaster.
- Go to the command line and type:
mingw32-make -f makefile.mingw
- All the example programs will be built for you
- You can use PixelToaster with Dev-C++ or any other IDE
on top of MinGW, just as long as you setup your own project files.
* UNIX: FreeBSD, Linux and Mac OS X
The supported display on FreeBSD and Linux is XWindows,
on Mac OS X Cocoa/OpenGL is used.
To compile the example programs, just use make:
make -f makefile.linux
make -f makefile.bsd
make -f makefile.apple
Pick the correct line based on your platform obviously,
I like to speed things up a bit my using a symbolic link:
For example on Mac OS X, I just go:
ln -s makefile.apple makefile
make
So everything is easy from this point on:
make test
make profile
make all
make docs
make clean
In order to make docs, you'll need to have doxygen installed:
http://www.doxygen.org
Alternatively, you can browse the docs for the latest release online:
http://www.pixeltoaster.com
Have fun!
[ How to Use PixelToaster ]
The API of PixelToaster is so easy to use, just look at the example programs
and you'll get the idea quickly.
However, what isnt obvious at first, is exactly what to do with the pixels!
Obviously, I cant teach software rendering in a few pages, but here is a quick
tutorial to get you started...
[ Pixels in Memory ]
Pixels are laid out in memory sequentially from top to bottom, left to right.
You can visualize this by rearranging each line of the image into a single chain,
each line bolted on at the end of the one above it, in one long line.
Lets say we have an image of dimensions 320x240, that is:
width = 320
height = 240
Pixel pixels[320*240];
Coordinate (0,0) is the top-left of the screen, and (319,239) is the bottom right.
Your x coordinate needs to be in range [0,319] and your y coordinate needs to be
in range [0,239]
We can find the index of a pixel given its (x,y) coordinates as follows:
int index = x + y * width;
So we can set get this pixel as follows:
pixel[index] = Pixel( 0, 0, 1 ); // set to blue
If you think about this closely, you are starting from the top-left of the screen,
advancing past all the whole lines above the line you want (y*width). This gets
you to the start of the line you want, so all if you have to do now is add "x"
and you have the index of the pixel at (x,y).
[ Pixel Format ]
You have the choice of working in truecolor or floating point color.
Truecolor has 32bit integer pixels with byte size rgb color components,
while floating point color has 128bits per pixel, with floating point values
for red, green, blue and alpha!
All things being equal, floating point is obviously slower than truecolor,
if for no reason other than requiring 4X the memory bandwidth! However, the
increased dynamic range and high precision of floating point make it a very
interesting format to work in.
[ Working in Floating Point Color ]
Floating point pixels made up of four floating point values:
struct FloatingPointPixel
{
float r,g,b,a;
};
You set the color of a pixel by setting its components.
The alpha value is for padding to 128bits. You can ignore it, or use it for
any purpose you like. It makes a nice z-buffer for a software renderer, or
alpha channel for compositing.
Each component is in range [0.0, 1.0f]
0.0f is minimum intensity (dark), while 1.0f is maximum intensity.
At the moment, values outside this range are automatically clamped.
In the future, these values will be used to indicate "high dynamic range"
to high contrast displays!
Here are some examples:
black = (0,0,0)
white = (1,1,1)
red = (1,0,0)
green = (0,1,0)
blue = (0,0,1)
really bright white = (1000000,1000000,1000000) ... !!!
[ Working in TrueColor ]
In truecolor, pixels are packed into 32bit integer values, like this:
[x][r][g][b]
r,g,b are the red, green and blue color components making up the color.
the x component is padding so the pixel takes up 32 bits.
Each component is in the range [0,255] with 0 being lowest intensity,
and 255 being maximum intensity.
therefore:
black is (0,0,0) -> 0x00000000
bright red is (255,0,0) -> 0x00FF0000
bright green is (0,255,0) -> 0x0000FF00
bright blue = (0,0,255) -> 0x000000FF
You can unpack and manually using masking and shift operations:
integer8 r = ( pixel & 0x00FF0000 ) >> 16;
integer8 g = ( pixel & 0x0000FF00 ) >> 8;
integer8 b = ( pixel & 0x000000FF );
And repack them again with shifts:
integer32 repacked = ( r << 16 ) | ( g << 8 ) | b;
Alternatively, you can treat your array of pixels as an array of
TrueColorPixel structs and use its union to access pixels:
TrueColorPixel pixel;
pixel.r = 128;
pixel.g = 10;
pixel.b = 192;
This is much easier! Just remember that each r,g,b value can only
in the range [0,255] when working with it - if you go outside this range
the color will wrap around from light to dark and vice versa.
[ Example Programs ]
* ExampleFloatingPoint
- how to open a display in floating point color and get pixels on the screen
* ExampleTrueColor
- the same thing, but in truecolor
* ExampleFullscreen
- how to open a fullscreen display
- fullscreen output is currently only supported in windows (DirectX 9.0)
and Mac OS X.
* ExampleKeyboardAndMouse
- how to receive keyboard and mouse events from a display
* ExampleTimer
- how to use the high resolution timer
* ExampleImage
- how to load a TGA image and display it
* ExampleMultiDisplay
- how to work with multiple displays (windowed only)
[ Licence ]
PixelToaster Framebuffer Library.
Copyright © 2004-2007 Glenn Fiedler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Glenn Fiedler