Zenipex

The Zenilib FAQ


Index

  1. Any bugs found recently? / I found a bug!
  2. Where do I extract the supporting files?
  3. When compiling, it can't find 'd3dx9.h' or 'SDL_stdinc.h' or ...
  4. When compiling, it can't find 'objbase.h'.
  5. error LNK2019: unresolved external symbol ...
  6. What is the best way to upgrade to a newer version of zenilib?
  7. I added an entry to one of the configuration XML files and zenilib can't find it.
  8. I can't get one your example .zips to work!
  9. Zenilib stutters for a second or two after starting!
  10. HEAP CORRUPTION DETECTED!
  11. My textures don't have transparency when loaded into zenilib!
  12. How do I tile a Texture?
  13. How do I avoid graphical errors at the edges of textured Quadrilaterals?
  14. How can I be sure my game is framerate independent?
  15. How can I make my game run faster?
  16. render_image(...) is too slow!
  17. Rendering Triangles/Quadrilaterals is too slow!
  18. How do I change the contents of a Vertex_Buffer?
  19. How do I get events to occur periodically?
  20. How do I scroll the screen in 2D?
  21. How do I use Parallelepiped for collisions in 2D?
  22. How can I reduce the size of my project for archival/submission purposes?
  23. Why does Visual Studio always ask me to recompile, even when it just compiled?
  24. How do I Texture a mesh in 3ds Max?
  25. How do I use a Model with Textures?

Any bugs found recently? / I found a bug!

Release Notes for 0.3.2.0

Always remember that a reproducable test case is worth a lot more than a bug report alone, but any report is better than nothing.

Where do I extract the supporting files?

To the same place you extracted zenilib. Please see the Start Guide for details.

When compiling, it can't find 'd3dx9.h' or 'SDL_stdinc.h' or ...

Please make sure that you have correctly set up the SDKs as described in the Development Environment installation guide. Then, be sure to extract the supporting files as described in the Start Guide.

When compiling, it can't find 'objbase.h'.

It is possible that you need to add paths for the Windows SDK. If you installed the Windows SDK 6.1, you may also need Include/Lib paths from 'C:\Program Files\Microsoft SDKs\Windows\v6.1'.

error LNK2019: unresolved external symbol ...

Ensure that you have '#include'ed <zenilib.h> at the top of all your source files. If you have and are still getting the error, it is likely that you are missing function definition.

What is the best way to upgrade to a newer version of zenilib?

  1. Read the changelog next to the download links on SourceForge.
  2. Back up your entire 'zenilib/' directory.
  3. Rename your 'zenilib/' directory if you haven't already.
  4. Extract a fresh copy of zenilib and the supporting files.
  5. Move or copy over the files you have created or modified. Typically, these will include a subset of the following:
    • zenilib/config/*
    • zenilib/fonts/*
    • zenilib/include/*
    • zenilib/models/*
    • zenilib/src/*
    • zenilib/textures/*
    • 'zenilib/Visual Studio 2008/*' <-- It is better to add your files to the project again rather than copying over these files. In some cases, you will lose new features or actually break zenilib.
    Note that some of these files may have been updated in the new version, and your existing files will need to be discarded or updated in order for zenilib to function.
  6. Test, test, test.

I added an entry to one of the configuration XML files and zenilib can't find it.

<!-- Make sure you didn't add it inside of a comment block. -->

I can't get one your example .zips to work!

  1. Make sure you do not have a 'zenilib/' directory on the desktop.
  2. Extract a fresh copy of zenilib with the supporting files. (See the Start Guide for details.)
  3. Test that it works correctly. If it does not, go back and follow the guide from start to finish. If it works, just close Visual Studio.
  4. Extract a copy of the example .zip over the existing 'zenilib/' directory. Replace all files when asked. If it does not ask to overwrite files, you have made an error. Examine the file structure of the example .zip and see how it corresponds to the existing 'zenilib/' directory.
  5. Switch to the SCU build target, Clean, Build, and Run.

Zenilib stutters for a second or two after starting!

Writing a game using zenilib is not like writing a game to use a text console. Zenilib has to load a number of images into memory, convert them into a format usable by the graphics card, and then send them out to graphics card memory. It has to follow similarly stressful steps in loading the other databases, and in initializing all the services underlying your game. Some of these steps are inherently done in the background after you are given control of the application. Your game must allow for a short grace period before you can expect good performance from the system. A title screen often does the job nicely, but just keep this in mind.

HEAP CORRUPTION DETECTED!

Heap Corruption often implies that Visual Studio needed to rebuild something, but wasn't smart enough to figure it out. Doing a clean+rebuild often solves that problem. You are most likely to encounter this error when exiting a Game_State.

There is also a chance that you need to add a virtual destructor to at least one of your base classes -- especially if derived classes contain Chronometers, Vertex_Buffers, or Models.

My textures don't have transparency when loaded into zenilib!

Open the image file in the GIMP (or in GIMP Portable).

Demo of Image Transparency in the GIMP

If you don't see a strange checkered background, you failed to create your image correctly, or you failed to export it correctly. Be sure not to flatten your image as you export it. And remember, always use .PNG.

How do I tile a Texture?

Set 'tile' to '1' in textures.xml and use texture coordinates outside the range [0,1].

// In render()

Quadrilateral<Vertex2f_Texture> quad(
  Vertex2f_Texture(Point2f(x    , y    ), Point2f(-1.0f, 0.0f)),
  Vertex2f_Texture(Point2f(x    , y + h), Point2f(-1.0f, 2.0f)),
  Vertex2f_Texture(Point2f(x + w, y + h), Point2f( 3.0f, 2.0f)),
  Vertex2f_Texture(Point2f(x + w, y    ), Point2f( 3.0f, 0.0f)));
Material material("texture");
quad.lend_Material(&material);

get_Video().render(quad);

How do I avoid graphical errors at the edges of textured Quadrilaterals?

Make sure the width and height of the image being loaded are both powers of 2. Make sure you disabled tiling of the particular texture in 'zenilib/config/textures.xml' (see zenilib/HOWTO.txt). Finally, be precise in your texture coordinates.

How can I be sure my game is framerate independent?

The only way to be absolutely sure is to use a fixed time step. So long as all changes to game state are made in 'perform_logic', you can accumulate the amount of time that has passed, and whenever it gets above a certain threshold, subtract off that fixed amount of time and perform a game step.

However, this isn't optimal for smoothness or performance, generally speaking. It is usually good enough to multiply all changes in motion by the amount of time that has passed since the previous frame. (e.g. position = time_step * velocity) The one caveat is that you probably need a bound on the size of a step to ensure stability, or you might just find yourself able to jump though a wall one time in a hundred.

How can I make my game run faster?

render_image(...) is too slow!

Try storing Quadrilaterals and rendering them manually:

// Possibly in a constructor

Vertex2f_Texture ul(Point2f(x    , y    ), Point2f(0.0f, 0.0f));
Vertex2f_Texture ll(Point2f(x    , y + h), Point2f(0.0f, 1.0f));
Vertex2f_Texture lr(Point2f(x + w, y + h), Point2f(1.0f, 1.0f));
Vertex2f_Texture ur(Point2f(x + w, y    ), Point2f(1.0f, 0.0f));
Material material("texture");

Quadrilateral<Vertex2f_Texture> quad(ul, ll, lr, ur);
quad.fax_Material(&material);

// In render()

get_Video().render(quad);

Rendering Triangles/Quadrilaterals is too slow!

Time to learn how to use Vertex Buffer Objects (VBOs). class Vertex_Buffer allows you to insert Triangle and Quadrilateral objects. After you give it all the Triangles and Quadrilaterals that you want it to be able to render, the Vertex_Buffer will be ready to render. Note that there will be no performance boost if the number of triangles in a Vertex_Buffers is very small. Note also that building a Vertex_Buffer is expensive, and should not be done every frame. (Recreating a Vertex_Buffer every frame defeats the purpose of using one.)

// Possibly in a constructor

Vertex_Buffer *vbo_ptr = new Vertex_Buffer;

vbo_ptr->give_quadrilateral(quad_ptr); // this pointer is dead to you
vbo_ptr->fax_quadrilateral(quad_ptr); // you can keep the pointer

// In render()

vbo_ptr->render();

Rendering a VBO is much faster than rendering a number of Triangles or Quadrilaterals individually. However, you can't change values within a VBO after it is created. So, if you want to move one around, the correct approach is to use Model/World matrix transformations.

Video &vr = get_Video();

vr.push_world_stack();
//vr.translate_scene(...);
//vr.rotate_scene(...);
//vr.scale_scene(...);

vbo_ptr->render();

vr.pop_world_stack();

How do I change the contents of a Vertex_Buffer?

You don't. Once a Vertex_Buffer is rendered, it becomes fixed. You must delete the old one and make a new one if you need to change the contents.

How do I get events to occur periodically?

The Chronometer<Time> class is helpful.

// Possibly in a constructor

m_seconds_passed = 0.0f;
m_chrono.start();

// In perform_logic()

const float seconds_passed = m_chrono.seconds();
const float time_step = seconds_passed - m_seconds_passed;
m_seconds_passed = seconds_passed;

Additionally, the Time values from Timer can be used directly when convenient, or when you want to keep your values from being affected when the user pauses the game.

How do I scroll the screen in 2D?

The first parameter of get_Video().set_2d(...) is an std::pair of 'Point2f's. By default, the first is (0, 0) and the second is (screen_width, screen_height). However, you can them to arbitrary coordinates in your 2D world.

Alternatively, the scene transformations described above can have the same effect.

How do I use Parallelepiped for collisions in 2D?

Pass in the upper left corner as the first parameter. For the next two parameters, pass in Vector3f(width, 0.0f, 0.0f) and Vector3f(0.0f, height, 0.0f). Finally, pass in Vector3f(0.0f, 0.0f, 1.0f) for the fourth and final parameter. Without specifying a height, the Parallelepipeds are degenerate and will give erroneous intersection/distance values. Of course, if your Parallelepipeds are not axis-aligned, you will have to do some extra work manipulating the parameters.

How can I reduce the size of my project for archival/submission purposes?

  1. Run 'zenilib/clean/zenilib_clean_extra_x86.py' in 'zenilib/' if Python is installed. Otherwise, run 'zenilib/clean/zenilib_clean_extra_x86.bat'.
  2. Run it to clear all "junk" files generated when working with Visual Studio, all Debug builds, and all x64 libs and DLLs. Even building solely with Visual Studio (and neither Xcode nor SCons), if all build targets are compiled, your 'zenilib/' directory can grow to over 800 MB. This reduces the default zenilib application to 21 MB, which compresses to 3.3 MB with 7-Zip.

Why does Visual Studio always ask me to recompile, even when it just compiled?

At least one of your header files or source files probably has a file modification time that is in the future. This can happen if you edit files on different computers that disagree about how to keep time. The solution is to update the modification times of all your header and source files. (This can be done by opening all of them, modifying them, and resaving them.)

How do I Texture a mesh in 3ds Max?

  1. Hit 'M' to open the Material Editor.
  2. If using '3ds Max Design 2009' rather than '3ds Max 2009':
    1. In the Material editor's 'Material' menu, click on 'Change Material/Map Type...'.
    2. Click on 'Standard' in the window that opens.
    3. Click on 'OK'.
  3. Click the 'Pick Material from Object' button (looks like a dropper).
  4. Left click on the mesh to get its current Material.
  5. Set the 'Ambient' and 'Diffuse' colors to white.
  6. Set the 'Specular' color to the approximate color of the object (or white if it is plastic).
  7. Go to 'Maps' tab and check the box next to 'Diffuse Color'.
  8. Click on the Map box (probably) containing 'None' on the same line.
  9. Select 'Bitmap' in the window that opens and click 'OK'.
  10. If using '3ds Max Design 2009' rather than '3ds Max 2009':
    1. In the Material editor's 'Coordinates' tab that appears after the Texture is set, uncheck 'Use Real-World Scale'.
    2. Set Tiling in both 'U' and 'V' to be 1.0 by default.
    3. Go to the Modify tab on the far right of 3ds Max.
    4. Uncheck 'Real-World Map Size' for the selected mesh. (You can uncheck this in the 'Create' tab as well, but it will apply only to newly created meshes.)
  11. Open an image and make sure the filename matches the *alias* you want to add to textures.txt. Note that this is not the filename in textures.txt.
  12. Left click on the mesh you want to apply the Material to.
  13. Back in the Material Editor, click the 'Assign Material to Selection' button (looks like 'Sphere->Box').
  14. Export as .3ds and 'Preserve 3ds Max's Texture Coordinates'.
  15. Make sure you add the 'Bitmap Parameter' you added to your mesh to textures.txt. To ensure that you get it right, I recommend reimporting the .3ds file and seeing what value is inside. It won't match what was set initially. Of course, if you get it wrong, zenilib will Error and tell you what you need to add in 'zenilib/stderr.txt'.

How do I use a Model with Textures?

3DS files seem to refer to textures by all caps file names. (At least this is the result when exporting from 3ds Max.) zenilib blindly looks in the Textures database to find the corresponding textures.

e.g. Applying car.jpg to part of a model in 3ds Max will result in a reference to CAR.JPG in the 3DS file. CAR.JPG can refer to whatever you like in the Textures database. (It could be an image loaded from car.png. It could just as easily be a Sprite.)

If your program throws an Error when you try to render the Model, you can check zenilib/stderr.txt for an error message telling you what Texture it was looking for.