First, thanks for this great library.
I have learned OpenGL by reading the Redbook (OpenGL Programming Guide). Since theory is nothing without practice, I have implemented its examples with the LWJGL in Java. The examples from the book are very helpful in my opinion and answer many of the questions I've seen around here.
I am done with all chapters and made them available for download along with some more information here:
http://ciardhubh.de/node/13 (http://ciardhubh.de/node/13)
This is probably interesting for anybody who wants to learn OpenGL with the help of this book and the LWJGL, too. Whether you just want to see the examples running or whether you want to see how you can get the desired effect in Java, this might be a help.
The code is based on the 2nd version of the book and LWJGL 2.
An older version (1.1) of the book can be found here for free: http://www.glprogramming.com/red/
The original C source code can be found here: http://www.opengl.org/resources/code/samples/redbook/
I also wrote a small launcher application to conveniently pick and run examples. It includes all libraries and no setup is required:
(http://ciardhubh.de/images/lwjgl_examples_launcher.png)
Here is a list of the examples which includes a topic for each example, for those without the book:
Example | Implemented | Part Of | Original File | Topic | Note |
1-1 | no | 1-2 | | Hello World | |
1-2 | yes | | hello.c | Hello World | |
1-3 | yes | | double.c | Double Buffering | |
|
|
|
|
|
|
2-1 | no | 1-3 | | Viewport Setup | |
2-2 | no | | | Use of glVertex*() | Only a collection of code snippets. |
2-3 | yes | | | Primitive Drawing | |
2-4 | yes | | | Primitive Drawing | |
2-5 | yes | | lines.c | Line Stippling | |
2-6 | yes | | polys.c | Polygon Stippling | |
2-7 | yes | | | Edge Marking | |
2-8 | no | | | Surface Normals | Minimal code snippet without any data. |
2-9 | yes | | varray.c | Vertex Arrays | |
2-10 | no | 2-9 | | Vertex Arrays | |
2-11 | yes | | | Vertex Arrays | |
2-12 | no | 2-11 | | Vertex Arrays | |
2-13 | no | 2-11 | | Vertex Arrays | |
2-14 | no | | | Vertex Arrays | glMultiDrawElements() does not exist in LWJGL |
2-15 | no | | | Vertex Arrays | |
2-16 | yes | | | Vertex Array Buffers | |
2-17 | yes | | | Vertex Array Buffers | |
2-18 | no | 2-17 | | Vertex Array Buffers | |
2-19 | no | 2-17 | | Vertex Array Buffers | |
2-20 | yes | | | Surface Subdivision | |
2-21 | no | 2-20 | | Surface Subdivision | |
2-22 | no | | | Surface Subdivision | Vital helper functions are missing. |
|
|
|
|
|
|
3-1 | yes | | cube.c | Modelling Transformation | |
3-2 | yes | | model.c | Modelling Transformation | |
3-3 | no | | | Projection Transformation | Vital helper functions are missing. |
3-4 | yes | | | Matrix Stack | |
3-5 | yes | | clip.c | Clipping Planes | |
3-6 | yes | | planet.c | Transformation Composition | |
3-7 | yes | | robot.c | Transformation Composition | |
3-8 | yes | | unproject.c | Reverse Projection | |
|
|
|
|
|
|
4-1 | yes | | smooth.c | Shading Model | |
|
|
|
|
|
|
5-1 | yes | | light.c | Lighting | |
5-2 | no | 5-1 | | Lighting | |
5-3 | yes | | | Lighting | |
5-4 | no | 5-1 | | Lighting | |
5-5 | yes | | | Lighting | |
5-6 | yes | | movelight.c | Lighting | |
5-7 | yes | | | Lighting | |
5-8 | yes | | material.c | Lighting and Materials | |
5-9 | yes | | colormat.c | Lighting and Materials | |
|
|
|
|
|
|
6-1 | yes | | blendeqn.c | Blending | |
6-2 | yes | | alpha.c | Blending | |
6-3 | yes | | alpha3D.c | Blending | |
6-4 | yes | | aargb.c | Antialiasing | |
6-5 | no | | aaindex.c | Anti-aliasing | glutSetColor() is missing in the LWJGL. |
6-6 | yes | | multisamp.c | Anti-aliasing | |
6-7 | yes | | fog.c | Fog | |
6-8 | no | | fogindex.c | Fog | glutSetColor() is missing in the LWJGL. |
6-9 | yes | | fogcoord.c | Fog | |
6-10 | yes | | pointp.c | Point Parameters | |
6-11 | yes | | polyoff.c | Polygon Offset | |
|
|
|
|
|
|
7-1 | yes | | torus.c | Display Lists | |
7-2 | yes | | list.c | Display Lists | |
7-3 | yes | | | Display Lists | |
7-4 | no | 7-5 | | Display Lists | |
7-5 | yes | | stroke.c | Display Lists | |
7-6 | no | 7-8 | | Display Lists | |
7-7 | no | 7-8 | | Display Lists | |
7-8 | yes | | | Display Lists | |
7-9 | yes | | | Display Lists | |
|
|
|
|
|
|
8-1 | yes | | drawf.c | Bitmap Font | |
8-2 | yes | | font.c | Bitmap Font | |
8-3 | yes | | image.c | Use of glDrawPixels() | |
8-4 | no | 8-3 | | Use of glDrawPixels() | |
8-5 | yes | | colortable.c | Colour Table | |
8-6 | yes | | convolution.c | Convolution Filters: | |
8-7 | yes | | colormatix.c | Colour Replacement | |
8-8 | yes | | histogram.c | Histogram | |
8-9 | yes | | minmax.c | Min-Max Pixel Values | |
|
|
|
|
|
|
9-1 | yes | | checker.c | Texturing | |
9-2 | yes | | | Texturing | |
9-3 | yes | | texsub.c | Texturing | |
9-4 | yes | | texture3d.c | 3D Texturing | |
9-5 | yes | | mipmap.c | Mipmaps | |
9-6 | yes | | | Mipmaps | |
9-7 | yes | | texbind.c | Texture Objects | |
9-8 | yes | | texgen.c | Texture-Coordinate Generation | |
9-9 | yes | | cubemap.c | Cubemap | |
9-10 | yes | | multitex.c | Multi-Texturing | |
9-11 | no | 9-10 | | Multi-Texturing | |
9-12 | no | 9-10 | | Multi-Texturing | |
9-13 | no | 9-16 | | Combiner Functions | |
9-14 | no | 9-16 | | Combiner Functions | |
9-15 | no | 9-16 | | Combiner Functions | |
9-16 | yes | | combiner.c | Combiner Functions | |
9-17 | yes | | shadowmap.c | Shadow Mapping | |
9-18 | no | 9-17 | shadowmap.c | Shadow Mapping | |
9-19 | no | 9-17 | shadowmap.c | Shadow Mapping | |
|
|
|
|
|
|
10-1 | yes | | stencil.c | Stencil Test | |
10-2 | yes | | | Occlusion Query | |
10-3 | no | 10-2 | | Occlusion Query | |
10-4 | yes | | accpersp.c | Scene Anti-alising | |
10-5 | no | 10-4 | accpersp.c | Scene Anti-alising | |
10-6 | yes | | accanti.c | Scene Anti-alising | |
10-7 | yes | | dof.c | Depth of Field | |
|
|
|
|
|
|
11-1 | no | | tess.c | Tesselation | GLU tesselation is not supported by LWJGL. |
11-2 | no | | tess.c | Tesselation | GLU tesselation is not supported by LWJGL. |
11-3 | no | | tess.c | Tesselation | GLU tesselation is not supported by LWJGL. |
11-4 | yes | | quadric.c | Quadrics | |
|
|
|
|
|
|
12-1 | yes | | bezcurve.c | Bezier Functions | |
12-2 | yes | | bezsurf.c | Bezier Functions | |
12-3 | yes | | bezmesh.c | Bezier Functions | |
12-4 | yes | | texturesurf.c | Bezier Functions | |
12-5 | no | | surface.c | NURBS | GLU NURBS are not supported by LWJGL. |
12-6 | no | | surfpoints.c | NURBS | GLU NURBS are not supported by LWJGL. |
12-7 | no | | surfpoints.c | NURBS | GLU NURBS are not supported by LWJGL. |
12-8 | no | | trim.c | NURBS | GLU NURBS are not supported by LWJGL. |
|
|
|
|
|
|
13-1 | no | 13-2 | | Name Stack | |
13-2 | yes | | select.c | Selection Mode | |
13-3 | yes | | picksquare.c | Picking | |
13-4 | yes | | | Multiple Names | |
13-5 | no | 13-4 | | Multiple Names | |
13-6 | yes | | pickdepth.c | Picking with Depth Values | |
13-7 | yes | | feedback.c | Feedback Mode | |
|
|
|
|
|
|
14-1 | yes | | | Error Handling | |
14-2 | yes | | | Querying Extension Capabilities | Replaced 14-2 code with gluCheckExtension(). |
14-3 | no | | | WGL Extension Location | Not supported by LWJGL |
|
|
|
|
|
|
15-1 | yes | | | Point Sprite | |
15-2 | no | 0-2 | | OpenGL Shading Language | OpenGL 2 version in 0-2 (instead of ARB extension) |
15-3 | no | 0-2 | | OpenGL Shading Language | OpenGL 2 version in 0-2 (instead of ARB extension) |
15-4 | no | | | OpenGL Shading Language | Incomplete code snippet |
15-5 | no | | | OpenGL Shading Language | Incomplete code snippet |
15-6 | no | | | OpenGL Shading Language | Incomplete code snippet |
15-7 | no | | | OpenGL Shading Language | Incomplete code snippet |
|
|
|
|
|
|
0-1 | yes | | | Accumulation Buffer Motion Blur | |
0-2 | yes | | | Simple GLSL vertex and fragment shaders | |
DownloadSource: http://ciardhubh.de/download/lwjgl_redbook_examples_src_2009-01-26.zip
Executable with launcher (requires Java 6): http://ciardhubh.de/download/lwjgl_redbook_examples_bin_2009-01-26.zip
Any feedback - whether you think they are useful or not, hard/easy to understand, etc. - is appreciated.
Added examples of chapter 8 and chapter 9.
Edit:
Finished chapter 9.
Edit2:
Added example 8-6, which is finally working.
This looks great (haven't worked through it yet, though). Thanks!
i think there is an error on 9_17 dont know if its my card or not (ATI radeon x1400)
(http://users.on.net/~bobjob/temp.JPG)
Quote from: bobjob on September 22, 2008, 00:29:42
i think there is an error on 9_17 dont know if its my card or not (ATI radeon x1400)
...
That's how it looks on my computer, too. It's probably not intended to look this way, but there is no screenshot on the original examples' site of this particular example and I don't have the time to set up the tools to compile the C example myself.
I assume that there is a problem with depth values when the texture is applied. I'm basically doing the same things as in the original example, though. So I'm not quite sure where the problem lies. Maybe I did something wrong or it's another bug in the original. If anybody has any hints I'd be happy to know.
Awesome job,
your work is highly appreciated,
Thanks.
Quote from: blingo on October 17, 2008, 23:00:14
Awesome job,
your work is highly appreciated,
Thanks.
Thank you, I'm glad somebody likes it ;D
I just updated the examples. Chapters 10 to 13 are now included. There's also a new launcher, so you don't have to set up libraries and manually run each example.
Hi~ thanks your Demo ,but i got some problem on it
In your Example 3-6 the plant need to run by hand
if (eventKey == Keyboard.KEY_D && Keyboard.isKeyDown(Keyboard.KEY_D)) {
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ||
Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
day = (day - 10) % 360;
} else {
day = (day + 10) % 360;
}
}
...etc
and i want the plant run by itself
this is my code:
protected void logic(long timeDelta) {
day = (day + 10) % 360;
year = (year + 5) % 360;
}
the Base class had been set
protected void run() {
while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Display.isCloseRequested()) {
now = System.currentTimeMillis();
timeDelta = now - lastTime;
lastTime = now;
if (Display.isVisible()) {
logic(timeDelta);
render();
} else {
if (Display.isDirty()) {
render();
}
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
}
}
Display.update();
}
}
but it's don't work.... plant run so fast...
i also check the FullScreenWindowedTest (http://lwjgl.org/demos.php)
while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Display.isCloseRequested()) {
if (Display.isVisible()) {
// check keyboard input
processKeyboard();
// do "game" logic, and render it
logic();
render();
} else {
// no need to render/paint if nothing has changed (ie. window
// dragged over)
if (Display.isDirty()) {
render();
}
// don't waste cpu time, sleep more
try {
Thread.sleep(100);
} catch (InterruptedException inte) {
}
}
// Update window
Display.update();
}
the FullScreenWindowedTest runs well but my code is not
why?
Quote from: iamzealotwang on October 24, 2008, 09:01:25
protected void logic(long timeDelta) {
day = (day + 10) % 360;
year = (year + 5) % 360;
}
This always runs at maximum speed, i.e. as fast as your computer can render the scene. That is why it's too fast. The mentioned Thread.sleep() is only executed if the application is not visible (e.g. minimised). Otherwise it is skipped.
To run the animation at a better speed, you have to make it dependent on the time passed since the last frame (the above is FPS dependent), e.g.:
protected void logic(long timeDelta) {
day = (day + DEGREES_PER_MILLISECOND * timeDelta) % 360;
year = (year + DEGREES_PER_MILLISECOND * timeDelta) % 360;
}
Where DEGREES_PER_MILLISECOND is the number of degrees you want to move per millisecond; something like 0.05f for example.
Thanks~
Now I set my demo likes:
private static final int FPS = 60;
private static final long SLLEEP_TIME = 1000/FPS;
protected void run() {
while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Display.isCloseRequested()) {
now = System.currentTimeMillis();
timeDelta = now - lastTime;
lastTime = now;
if (Display.isVisible()) {
logic();
render();
} else {
if (Display.isDirty()) {
render();
}
}
if(timeDelta < SLLEEP_TIME)
try {
Thread.sleep(SLLEEP_TIME-timeDelta);
} catch (InterruptedException ex) {
}
Display.update();
}
}
and it look's great now
O(∩_∩)O
Quote from: iamzealotwang on October 27, 2008, 11:14:40
try {
Thread.sleep(SLLEEP_TIME-timeDelta);
} catch (InterruptedException ex) {
}
If you want to sync to a certain framerate, it is probably better to use Display.sync(...). Just replace the cited code with
Display.sync(FPS);
use http://lwjgl.org/javadoc/org/lwjgl/Sys.html#getTime() instead :) or use Display.sync() :)
this is very much appreciated, thanks for your work.
Quote from: ilazarte on January 08, 2009, 07:16:17
this is very much appreciated, thanks for your work.
Thanks.
By the way, I've finished all chapters and updated the downloads. Time to get a book about GLSL or some other advanced topic, I guess :D
Interestingly enough I couldn't run the examples from the jar, my guess is some exception was being swallowed when I tried to click run. However, downloading the source and running them from Eclipse is working great. Thanks again. Hard to believe its been almost a year since I've had a chance to look at lwjgl. But work/life is finally opening up some time so .... :)