### Custom pipeline example: myInstance, myRender, makeMyPipeline Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/pipeline.md Defines a custom rw::ObjPipeline with instance and render callbacks. Note that ObjPipeline::init fills all impl slots with no-ops, so unset callbacks are safe; custom pipelines must be assigned per atomic via pi->pipeline = pipe or installed as the driver's default pipeline. ```cpp #include static void myInstance(rw::ObjPipeline *pipe, rw::Atomic *atomic) { // per-platform code would allocate vertex/index buffers here. // For a null-platform pass-through we do nothing. (void)pipe; (void)atomic; } static void myRender(rw::ObjPipeline *pipe, rw::Atomic *atomic) { // draw the atomic's meshes rw::Geometry *geo = atomic->geometry; rw::MeshHeader *mh = geo->meshHeader; for(uint32 i = 0; i < mh->numMeshes; i++){ rw::Mesh *m = &mh->getMeshes()[i]; // e.g. m->material->texture->raster->bind(0); // draw m->numIndices indices via the device } } rw::ObjPipeline* makeMyPipeline(void) { rw::ObjPipeline *pipe = rw::ObjPipeline::create(); pipe->impl.instance = myInstance; pipe->impl.render = myRender; pipe->impl.uninstance = nil; // falls back to no-op if nil? no: return pipe; // set it or leave the no-op default! } ``` -------------------------------- ### Engine::start Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/engine.md Starts the engine by creating the device context and constructing engine and driver plugins. Transitions the engine state from Opened to Started. ```APIDOC ## Engine::start ### Description Starts the engine by creating the device context and constructing engine and driver plugins. Transitions the engine state from Opened to Started. ### Method Engine::start ### Signature ```cpp static bool32 start(void); ``` ### Returns - `bool32` - Returns 1 on success. ### Errors - Raises `ERR_ENGINESTART` unless state is `Opened`. ### Details Runs `device.system(DEVICEINIT, nil, 0)` (context creation), constructs the engine and driver plugins (`s_plglist.construct`), runs `device.system(DEVICEFINALIZE, nil, 0)`, and registers the TGA/BMP/PNG image file formats (`Image::registerFileFormat`). Transition: `Opened` → `Started`. ``` -------------------------------- ### Minimal engine lifecycle Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/engine.md Shows the required sequence: init, open, get video mode, start, render, then stop, close, term. Uses GL3 build with GLFW window. Returns 1 on failure at each step. ```cpp #include int main(void) { // 1) init if(!rw::Engine::init()) return 1; // 2) open — GL3 build rw::EngineOpenParams openParams; GLFWwindow *win = nil; openParams.window = &win; openParams.width = 640; openParams.height = 480; openParams.windowtitle = "hello"; if(!rw::Engine::open(&openParams)) return 1; // 3) pick a video mode rw::VideoMode mode; rw::Engine::getVideoModeInfo(&mode, rw::Engine::getCurrentVideoMode()); // 4) start rendering if(!rw::Engine::start()) return 1; // ... render frames ... // 5) shutdown in reverse order rw::Engine::stop(); rw::Engine::close(); rw::Engine::term(); return 0; } ``` -------------------------------- ### Install dumprwtree executable Source: https://github.com/aap/librw/blob/master/tools/dumprwtree/CMakeLists.txt Installs the dumprwtree executable to the configured binary directory when LIBRW_INSTALL is enabled. ```cmake if(LIBRW_INSTALL) install(TARGETS dumprwtree RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ) endif() ``` -------------------------------- ### Example: attaching and running an HAnim clip Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/hanim.md Shows how to create a hierarchy from a clump's bone frames, attach it, and tick an animation. setupHAnim creates the hierarchy with UPDATELTMS and sizeof(HAnimInterpFrame) as maxKeySize. tickHAnim sets the current animation, advances time, and updates matrices. ```cpp #include // Given a clump whose frames are already marked as bones, create // a hierarchy, attach the animation and tick it. rw::HAnimHierarchy* setupHAnim(rw::Clump *clump, int32 numBones) { int32 flags[32], ids[32]; for(int32 i = 0; i < numBones; i++){ flags[i] = 0; ids[i] = i; // bone ids matching the ANIM keys } rw::HAnimHierarchy *hier = rw::HAnimHierarchy::create( numBones, flags, ids, rw::HAnimHierarchy::UPDATELTMS, // update LTM matrices sizeof(rw::HAnimInterpFrame)); hier->attach(); // link to clump frame hierarchy return hier; } void tickHAnim(rw::HAnimHierarchy *hier, rw::Animation *anim, float dt) { if(!hier->interpolator->setCurrentAnim(anim)) return; hier->interpolator->addTime(dt); hier->updateMatrices(); } ``` -------------------------------- ### Example: locating a hierarchy at render time Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/hanim.md Shows how to retrieve the HAnim hierarchy from an atomic's frame during rendering. Uses get() first, then falls back to find() to search siblings/children. Calls updateMatrices() before drawing to upload bone matrices. ```cpp #include void renderSkinned(rw::Atomic *atomic) { // skeletal atomic; get hierarchy through the skin plugin or frame rw::Frame *f = atomic->getFrame(); rw::HAnimHierarchy *hier = rw::HAnimHierarchy::get(f); if(hier == nil) hier = rw::HAnimHierarchy::find(f); // search siblings/children if(hier) hier->updateMatrices(); // upload before drawing atomic->render(); } ``` -------------------------------- ### Setup and render camera with framebuffer and zbuffer Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/scene.md Shows how to create a camera with a framebuffer and zbuffer, set near/far planes and FOV, then render a clump each frame. Includes optional frustum culling and flushing im3d batches. ```cpp // Camera setup — attach a framebuffer+zbuffer, then render each frame. rw::Camera* setupCamera(int w, int h) { rw::Camera *cam = rw::Camera::create(); cam->setFrame(rw::Frame::create()); cam->frameBuffer = rw::Raster::create(w, h, 0, rw::Raster::CAMERA); cam->zBuffer = rw::Raster::create(w, h, 0, rw::Raster::ZBUFFER); cam->setNearPlane(0.1f); cam->setFarPlane(400.0f); // fov: 70° horizontal on a 16:9 backbuffer cam->setFOV(70.0f, (float)w / h); return cam; } void renderFrame(rw::Camera *cam, rw::Clump *clump) { rw::RGBA clear = { 0, 0, 0, 255 }; // optionally frustum-cull each atomic before rendering: // rw::Atomic *atom; // FORLIST(lnk, clump->atomics){ // atom = rw::Atomic::fromClump(lnk); // if(cam->frustumTestSphere(atom->getWorldBoundingSphere()) // == rw::Camera::SPHEREOUTSIDE) continue; // atom->render(); // } cam->clear(&clear, rw::Camera::CLEARIMAGE | rw::Camera::CLEARZ); cam->beginUpdate(); clump->render(); rw::im3d::End(); // flush any outstanding im3d batches cam->endUpdate(); cam->showRaster(0); } ``` -------------------------------- ### Example of PLUGINOFFSET usage with GETANISOTROPYEXT Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/lists-plugins.md Shows how a plugin exposes per-object data via PLUGINOFFSET, using an extern offset variable and a macro that retrieves an int32 value from a texture. ```cpp extern int32 hAnimOffset; #define GETANISOTROPYEXT(texture) PLUGINOFFSET(int32, texture, rw::anisotOffset) ``` -------------------------------- ### rw::Engine::start Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/engine.md Starts the rendering process. Must be called after opening the engine and before rendering frames. ```APIDOC ## rw::Engine::start ### Description Starts the rendering process. Must be called after opening the engine and before rendering frames. ### Method C++ function ### Signature ```cpp bool rw::Engine::start(); ``` ### Parameters None. ### Return Value - **bool** - Returns true on success, false on failure. ### Example ```cpp if(!rw::Engine::start()) { // handle error } ``` ``` -------------------------------- ### Install headers and library targets with CMake Source: https://github.com/aap/librw/blob/master/src/CMakeLists.txt Defines installation rules for librw when LIBRW_INSTALL is enabled. Installs public headers to the configured include directory, platform-specific headers under src/d3d, src/ps2, and src/gl, and the librw target with export set librw-targets. ```cmake if(LIBRW_INSTALL) install( FILES "${PROJECT_SOURCE_DIR}/args.h" "${PROJECT_SOURCE_DIR}/rw.h" DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}" ) install( FILES base.err rwbase.h rwcharset.h rwerror.h rwplg.h rwrender.h rwengine.h rwpipeline.h rwobjects.h rwanim.h rwplugins.h rwuserdata.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src" ) install( FILES d3d/rwxbox.h d3d/rwd3d.h d3d/rwd3d8.h d3d/rwd3d9.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/d3d" ) install( FILES ps2/rwps2.h ps2/rwps2plg.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/ps2" ) install( FILES gl/rwwdgl.h gl/rwgl3.h gl/rwgl3plg.h gl/rwgl3shader.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/gl" ) install( FILES gl/glad/glad.h gl/glad/khrplatform.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/gl/glad" ) install( TARGETS librw EXPORT librw-targets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() ``` -------------------------------- ### Instancing helpers example: packVertices and minVertForMesh Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/pipeline.md Shows how to pack generic geometry into an interleaved ARGB + float3 + float2 stream using rw::instColor, rw::instV3d, and rw::instTexCoords, and how to compute the minimum vertex index for a mesh using rw::findMinVertAndNumVertices. The dst layout is [RGBA 4B][XYZ 12B][UV 8B] with 'stride' byte rows. ```cpp #include // Pack generic geometry into an interleaved ARGB + float3 + float2 stream. void packVertices(rw::Geometry *geo, uint8 *dst, uint32 stride) { uint32 numVerts = geo->numVertices; rw::instColor(rw::VERT_RGBA, dst, geo->colors, numVerts, stride); rw::instV3d(rw::VERT_FLOAT3, dst + 4, geo->morphTargets[0].vertices, numVerts, stride); rw::instTexCoords(rw::VERT_FLOAT2, dst + 16, geo->texCoords[0], numVerts, stride); // dst layout: [RGBA 4B][XYZ 12B][UV 8B] with 'stride' byte rows } uint32 minVertForMesh(rw::Mesh *m) { uint32 minVert; int32 numVerts; rw::findMinVertAndNumVertices(m->indices, m->numIndices, &minVert, &numVerts); return minVert; } ``` -------------------------------- ### Example: printing a HUD line Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/charset.md Shows how to initialize the charset module, create a Charset with foreground/background colors, print a string at (8,8) with hideSpaces=1, and clean up. The comment notes that the charset draws into its own raster, so you must blit it to the camera framebuffer or push it as the current context. ```cpp #include // Show one frame of text on the camera's framebuffer. void drawHUD(rw::Camera *cam, const char *text) { static rw::RGBA fg = { 255, 255, 255, 255 }; static rw::RGBA bg = { 0, 0, 0, 255 }; if(!rw::Charset::open()) // initialize module (once) return; rw::Charset *charset = rw::Charset::create(&fg, &bg); if(charset == nil) return; // Attach the charset to the camera framebuffer and print. // The charset draws into its own raster, so copy/blit it: charset->print(text, 8, 8, 1); // e.g. raster blit: cam->frameBuffer->lock(...); copy pixels; // cam->frameBuffer->unlock(...); // or push the charset raster as current context and render it: rw::Raster *prev = rw::Raster::pushContext(cam->frameBuffer); if(prev) rw::Raster::popContext(); charset->destroy(); } ``` -------------------------------- ### Example: buffered printing Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/charset.md Shows how to batch multiple strings with printBuffered and then flush once with rw::Charset::flushBuffer(). The makeHud helper opens the module and creates a Charset; drawStats prints a label and a formatted integer, then flushes the buffer. ```cpp #include // Batch multiple strings, then flush once. rw::Charset* makeHud(rw::RGBA fg, rw::RGBA bg) { rw::Charset::open(); return rw::Charset::create(&fg, &bg); } void drawStats(rw::Charset *cs, int32 x, int32 y, int32 fps) { char line[64]; cs->printBuffered("FPS", x, y, 1); snprintf(line, sizeof(line), "%d", fps); cs->printBuffered(line, x + 32, y, 1); rw::Charset::flushBuffer(); } ``` -------------------------------- ### Registering a custom Frame plugin with rw::Frame::registerPlugin Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/lists-plugins.md Complete example of a custom Frame plugin: defines a data struct, constructor, stream read/write/size callbacks, and registration functions. Must run after rw::Engine::init() and before any Frame is created. Uses PLUGINOFFSET to access per-object data. ```cpp #include struct MyData { int32 id; float32 value; }; static int32 myOffset; // filled by registerPlugin static void* myCtor(void *object, int32 offset, int32 size) { PLUGINOFFSET(MyData, object, offset)->id = 0; PLUGINOFFSET(MyData, object, offset)->value = 0.0f; return object; } static Stream* myRead(Stream *stream, int32, void *object, int32 offset, int32) { MyData *d = PLUGINOFFSET(MyData, object, offset); d->id = stream->readI32(); d->value = stream->readF32(); return stream; } static Stream* myWrite(Stream *stream, int32, void *object, int32 offset, int32) { MyData *d = PLUGINOFFSET(MyData, object, offset); stream->writeI32(d->id); stream->writeF32(d->value); return stream; } static int32 mySize(void *object, int32 offset, int32) { return sizeof(MyData); } // must run AFTER rw::Engine::init() and BEFORE any Frame is created void registerMyPlugin(void) { myOffset = rw::Frame::registerPlugin(sizeof(MyData), 0x12345678, myCtor, nil, nil); rw::Frame::registerPluginStream(0x12345678, myRead, myWrite, mySize); // optionally: // rw::Frame::setStreamRightsCallback(0x12345678, myRights); // rw::Frame::setStreamAlwaysCallback(0x12345678, myAlways); } void useMyData(rw::Frame *f) { MyData *d = PLUGINOFFSET(MyData, f, myOffset); d->value = 3.14f; } ``` -------------------------------- ### Apply platform target to dumprwtree Source: https://github.com/aap/librw/blob/master/tools/dumprwtree/CMakeLists.txt Calls the librw_platform_target function with the INSTALL option for the dumprwtree target. ```cmake librw_platform_target(dumprwtree INSTALL) ``` -------------------------------- ### Building a clump, lighting and rendering it Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/scene.md Shows how to assemble a clump from a geometry, attach lights, and render through a world. The example creates a clump with a triangle geometry, adds ambient and directional lights, and uses rw::World::enumerateLights to find illuminating lights. Note that the WorldLights arrays must be sized before calling enumerateLights, and world->destroy() does not destroy the clump. ```cpp #include // Assemble a clump from a geometry and give it a pipeline. rw::Atomic* makeAtomic(rw::Geometry *geo, rw::Frame *parent) { rw::Frame *f = rw::Frame::create(); if(parent) parent->addChild(f); rw::Atomic *a = rw::Atomic::create(); a->setFrame(f); a->setGeometry(geo, 0); // default pipeline is installed by the driver; instance once: a->instance(); return a; } void demo(rw::Camera *cam) { rw::Frame *root = rw::Frame::create(); rw::Clump *clump = rw::Clump::create(); clump->setFrame(root); rw::Geometry *geo = rw::Geometry::create(3, 1, rw::Geometry::POSITIONS); geo->lock(rw::Geometry::LOCKALL); geo->morphTargets[0].vertices[0] = rw::makeV3d(0,0,0); geo->morphTargets[0].vertices[1] = rw::makeV3d(1,0,0); geo->morphTargets[0].vertices[2] = rw::makeV3d(0,1,0); geo->unlock(); geo->calculateBoundingSphere(); geo->buildMeshes(); clump->addAtomic(makeAtomic(geo, root)); clump->render(); // renders all atomics // lights: one ambient + one directional, attached to frames rw::Light *amb = rw::Light::create(rw::Light::AMBIENT); amb->setColor(0.3f, 0.3f, 0.3f); amb->setFlags(rw::Light::LIGHTATOMICS); amb->setFrame(rw::Frame::create()); rw::Light *dir = rw::Light::create(rw::Light::DIRECTIONAL); dir->setColor(1.0f, 1.0f, 1.0f); dir->setFrame(rw::Frame::create()); dir->getFrame()->matrix.lookAt(rw::makeV3d(0,0,-1), rw::makeV3d(0,1,0)); // World-based enumeration rw::World *world = rw::World::create(); world->addClump(clump); world->addLight(amb); world->addLight(dir); world->addCamera(cam); rw::WorldLights lights; lights.numDirectionals = 8; // capacity! before calling lights.numLocals = 16; // capacity! before calling rw::Light *dirs[8], *locals[16]; lights.directionals = dirs; lights.locals = locals; rw::Atomic *atom = rw::Atomic::fromClump(clump->atomics.link.next); world->enumerateLights(atom, &lights); // dirs[0..lights.numDirectionals) + locals[0..lights.numLocals) // are now the illuminating lights world->render(); // render-through-world world->destroy(); // destroys clump membership, not clump clump->destroy(); } ``` -------------------------------- ### Example: storing per-material metadata Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/userdata.md Shows how to attach and read an integer array named "team" to a material. tagMaterial adds the array and sets its value; readTag finds the array and retrieves the value. Both return -1 or early-exit if the plugin is not registered or memory is exhausted. ```cpp #include void tagMaterial(rw::Material *mat) { // integer array "team" with one element int32 idx = rw::UserDataArray::materialAdd(mat, "team", rw::USERDATAINT, 1); if(idx < 0) return; // OOM or plugin not registered rw::UserDataExtension *ud = rw::UserDataExtension::get(mat); rw::UserDataArray *a = ud->get(ud->findIndex("team")); a->setInt(0, 42); } int32 readTag(rw::Material *mat) { int32 idx = rw::UserDataArray::materialFindIndex(mat, "team"); if(idx < 0) return -1; rw::UserDataArray *a = rw::UserDataArray::materialGet(mat, idx); return a->getInt(0); } ``` -------------------------------- ### Draw 3D line with rw::im3d and render-state setup Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/render.md Sets render states for depth testing, blending, and texture raster, then transforms two Im3DVertex vertices and renders a line. Requires calling rw::im3d::End() to flush before swap; the world matrix is created and destroyed within the function. ```cpp #include void drawLine3D(rw::V3d a, rw::V3d b) { // prepare render states rw::SetRenderState(rw::ZTESTENABLE, 1); rw::SetRenderState(rw::ZWRITEENABLE, 0); rw::SetRenderState(rw::SRCBLEND, rw::BLENDONE); rw::SetRenderState(rw::DESTBLEND, rw::BLENDZERO); rw::SetRenderStatePtr(rw::TEXTURERASTER, nil); rw::Im3DVertex verts[2]; verts[0].setX(a.x); verts[0].setY(a.y); verts[0].setZ(a.z); verts[0].setColor(255, 0, 0, 255); verts[1].setX(b.x); verts[1].setY(b.y); verts[1].setZ(b.z); verts[1].setColor(255, 0, 0, 255); rw::Matrix *world = rw::Matrix::create(); rw::im3d::Transform(verts, 2, world, rw::im3d::VERTEXXYZ | rw::im3d::VERTEXRGBA); rw::im3d::RenderLine(0, 1); rw::im3d::End(); // required to flush before swap world->destroy(); } ``` -------------------------------- ### Draw 2D sprite quad with rw::im2d::RenderIndexedPrimitive Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/render.md Sets up four Im2DVertex vertices with screen coordinates, color, and UVs, then renders a quad using an index list. The example uses the gl3 platform's Im2DVertex type and calls rw::im2d::RenderIndexedPrimitive with PRIMTYPETRILIST. ```cpp #include void drawQuad2D(int32 x, int32 y, int32 w, int32 h) { rw::Im2DVertex verts[4]; // platform Im2DVertex; here: gl3 // screen coords, rgba, uv verts[0].setScreenX(x); verts[0].setScreenY(y); verts[0].setScreenZ(0.5f); verts[0].setCameraZ(1.0f); verts[0].setColor(255, 255, 255, 255); verts[0].setU(0.0f, 1.0f); verts[0].setV(0.0f, 1.0f); verts[1].setScreenX(x + w); verts[1].setScreenY(y); verts[1].setScreenZ(0.5f); verts[1].setCameraZ(1.0f); verts[1].setColor(255, 255, 255, 255); verts[1].setU(1.0f, 1.0f); verts[1].setV(0.0f, 1.0f); verts[2].setScreenX(x + w); verts[2].setScreenY(y + h); verts[2].setScreenZ(0.5f); verts[2].setCameraZ(1.0f); verts[2].setU(1.0f, 1.0f); verts[2].setV(1.0f, 1.0f); verts[3].setScreenX(x); verts[3].setScreenY(y + h); verts[3].setScreenZ(0.5f); verts[3].setCameraZ(1.0f); verts[3].setU(0.0f, 1.0f); verts[3].setV(1.0f, 1.0f); uint16 indices[6] = { 0, 1, 2, 0, 2, 3 }; rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST, verts, 4, indices, 6); } ``` -------------------------------- ### Example: env-mapping a material Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/matfx.md Creates a material with environment mapping using rw::MatFX. Sets the environment texture, reference frame, coefficient, and disables framebuffer alpha blending. Also sets global env-map knobs envMapApplyLight and envMapUseMatColor. ```cpp #include rw::Material* makeEnvMaterial(rw::Texture *base, rw::Texture *envTex, rw::Frame *camFrame) { rw::Material *mat = rw::Material::create(); mat->setTexture(base); rw::MatFX::setEffects(mat, rw::MatFX::ENVMAP); rw::MatFX *fx = rw::MatFX::get(mat); fx->setEnvTexture(envTex); fx->setEnvFrame(camFrame); // reference frame for reflection fx->setEnvCoefficient(0.5f); fx->setEnvFBAlpha(0); // no framebuffer alpha blending // global env-map knobs rw::MatFX::envMapApplyLight = 1; rw::MatFX::envMapUseMatColor = 1; return mat; } ``` -------------------------------- ### Charset::open() Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/charset.md Initializes the charset module, building the glyph raster from the built-in VGA font. Must be called before create(). Returns false on failure (e.g., engine not started). ```APIDOC ## Charset::open() ### Description Initializes the charset module, building the glyph raster from the built-in VGA font. Must be called before create(). Returns false on failure (e.g., engine not started). ### Method static bool32 open(void) ### Returns - **bool32** - true on success, false on failure ``` -------------------------------- ### Create a custom shader via rw::gl3::Shader::create Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/gl3.md Builds a vertex and fragment shader from library-provided header strings plus custom GLSL code, then creates the shader through the registry. The example uses a minimal red fragment shader and a passthrough vertex shader. ```cpp // Creating a custom shader through the registry. rw::gl3::Shader* makeBlinnShader(void) { // use the library-provided vertex/fragment header strings const char *vs[] = { rw::gl3::shaderDecl, rw::gl3::header_vert_src, "#version 330 core\n" "layout(location=0) in vec3 aPos;\n" "void main(){ gl_Position = vec4(aPos,1.0); }", nil }; const char *fs[] = { rw::gl3::shaderDecl, rw::gl3::header_frag_src, "out vec4 fragColor;\n" "void main(){ fragColor = vec4(1,0,0,1); }", nil }; return rw::gl3::Shader::create(vs, fs); } ``` -------------------------------- ### PS2 real-hardware helper declarations (dmaFlip, dmaKick, beginFrame, etc.) Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/ps2.md Declarations for PS2-specific DMA, GIF/VIF packet, texture, and rendering helpers guarded by `#ifdef RW_PS2`. Use these to interact with the PS2 hardware directly, including DMA kicks, frame control, raster uploads, texture setup, and VU code upload. ```cpp void dmaFlip(int i); void dmaKick(void); extern rw::uint32 gifPacksz, gifBufSize; extern rw::uint32 vifPacksz, vifBufSize; extern QWord *gifPacket, *vifPacket; extern int path2Textures; extern int synchTextures; extern int gateTextures; extern int finishCycle; extern int32 doClipping; extern int32 doModulate2; extern QWord colorNoScale, colorTexScale; void beginFrame(int frame); void endFrame(float *t1, float *t2); void uploadRaster(Raster *raster); void setTexture(Raster *raster, uint32 addressU, uint32 addressV, uint32 filterMode); void flushGSRegs(void); void uploadVUCode(uint32 *code); void setMatrix(RawMatrix *combined, Matrix *world); void defaultAtomicRender(rw::ObjPipeline *pipe, Atomic *atomic); ``` -------------------------------- ### Pipeline and ObjPipeline class definitions Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/pipeline.md Defines the base Pipeline class and ObjPipeline subclass for per-platform conversion of Geometry into renderable buffers and drawing. Pipeline::init zeroes pluginID/pluginData and stores the platform; ObjPipeline::create always creates a PLATFORM_NULL pipeline with no-op impl functions. Platform-specific pipelines subclass ObjPipeline and install real callbacks. ```cpp struct Atomic; class Pipeline { public: uint32 pluginID; uint32 pluginData; int32 platform; void init(uint32 platform) { this->pluginID = 0; this->pluginData = 0; this->platform = platform; } }; class ObjPipeline : public Pipeline { public: void init(uint32 platform); static ObjPipeline *create(void); // always PLATFORM_NULL void destroy(void); // not the most beautiful way of doing things but still // better than virtual methods (i hope?). struct { void (*instance)(ObjPipeline *pipe, Atomic *atomic); void (*uninstance)(ObjPipeline *pipe, Atomic *atomic); void (*render)(ObjPipeline *pipe, Atomic *atomic); } impl; // just for convenience void instance(Atomic *atomic) { this->impl.instance(this, atomic); } void uninstance(Atomic *atomic) { this->impl.uninstance(this, atomic); } void render(Atomic *atomic) { this->impl.render(this, atomic); } }; ``` -------------------------------- ### Define lights executable and link librw libraries Source: https://github.com/aap/librw/blob/master/tools/lights/CMakeLists.txt Creates the lights WIN32 executable from main.cpp and lights.cpp, linking librw::skeleton and librw::librw privately. ```cmake add_executable(lights WIN32 main.cpp lights.cpp ) target_link_libraries(lights PRIVATE librw::skeleton librw::librw ) ``` -------------------------------- ### Engine::open(EngineOpenParams*) Source: https://github.com/aap/librw/blob/master/_autodocs/configuration.md Initializes the engine with platform-specific window and video parameters. The EngineOpenParams struct is defined per platform, and only the one for the compiled RWDEVICE exists. ```APIDOC ## Engine::open(EngineOpenParams*) ### Description Initializes the engine with platform-specific window and video parameters. The EngineOpenParams struct is defined per platform, and only the one for the compiled RWDEVICE exists. ### Method C++ function call ### Parameters #### EngineOpenParams (per platform) - **window** (`SDL_Window **` / `GLFWwindow **`) - Required (GL3) - Pointer to the window pointer; the backend creates/attaches the window, e.g. `SDL_CreateWindow` result assigned through it. - **fullscreen** (bool32) - Optional (SDL builds) - Request a fullscreen video mode. Default: 0. - **width** (int) - Required (GL3) - Initial window width. - **height** (int) - Required (GL3) - Initial window height. - **windowtitle** (const char *) - Required (GL3) - Window title string. - **window** (HWND) - Required (D3D9) - The HWND to present into. ### Notes - For RW_PS2, EngineOpenParams is empty. - GL3 window creation details: `openSDL2`/`openSDL3`/`openGLFW` in `src/gl/gl3device.cpp` store these fields, initialize the library (`SDL_InitSubSystem(SDL_INIT_VIDEO)` / `glfwInit()`), enumerate displays/video modes and create a GL context with a core profile preferring GL 3.3, falling back to GL 2.1 / GLES 3.1 / GLES 2.0. ``` -------------------------------- ### UserDataExtension struct definition Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/userdata.md Defines the plugin payload structure with a count and flat array of UserDataArray objects. Provides methods to add, remove, get, count, and find arrays, plus static get() overloads for each supported object type (Geometry, Frame, Camera, Light, Material, Texture). ```cpp struct UserDataExtension { int32 numArrays; UserDataArray *arrays; int32 add(const char *name, int32 datatype, int32 numElements); void remove(int32 n); int32 getCount(void) { return numArrays; } UserDataArray *get(int32 n) { return n >= numArrays ? nil : &arrays[n]; } int32 findIndex(const char *name); static UserDataExtension *get(Geometry *geo); static UserDataExtension *get(Frame *frame); static UserDataExtension *get(Camera *cam); static UserDataExtension *get(Light *light); static UserDataExtension *get(Material *mat); static UserDataExtension *get(Texture *tex); }; ``` -------------------------------- ### Apply platform target settings Source: https://github.com/aap/librw/blob/master/tools/camera/CMakeLists.txt Invokes librw_platform_target to apply platform-specific configuration to the camera target. ```cmake librw_platform_target(camera) ``` -------------------------------- ### UV transform setters/getters Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/matfx.md Set and get the base and dual UV transform matrices. ```APIDOC ## UV transform setters/getters ### Description Set and get the base and dual UV transform matrices. ### Methods - `void setUVTransformMatrices(Matrix *base, Matrix *dual);` - `void getUVTransformMatrices(Matrix **base, Matrix **dual);` ### Parameters - **base** (Matrix*) - Required - The base UV transform matrix. - **dual** (Matrix*) - Required - The dual UV transform matrix. ### Returns - `Matrix**` - Pointers to the base and dual matrices (output parameters). ``` -------------------------------- ### Dual setters/getters Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/matfx.md Set and get dual texture properties: second texture and blend factors. ```APIDOC ## Dual setters/getters ### Description Set and get dual texture properties: second texture and blend factors. ### Methods - `void setDualTexture(Texture *t);` - `void setDualSrcBlend(int32 blend);` - `void setDualDestBlend(int32 blend);` - `Texture *getDualTexture(void);` - `int32 getDualSrcBlend(void);` - `int32 getDualDestBlend(void);` ### Parameters - **t** (Texture*) - Required - The second texture to set. - **blend** (int32) - Required - The blend factor (source or destination). ### Returns - `Texture*` - The current dual texture. - `int32` - The current source blend factor. - `int32` - The current destination blend factor. ``` -------------------------------- ### Bump setters/getters Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/matfx.md Set and get bump mapping properties: bump texture, base texture, and coefficient. ```APIDOC ## Bump setters/getters ### Description Set and get bump mapping properties: bump texture, base texture, and coefficient. ### Methods - `void setBumpTexture(Texture *t);` - `void setBumpCoefficient(float32 coef);` - `Texture *getBumpTexture(void);` - `float32 getBumpCoefficient(void);` ### Parameters - **t** (Texture*) - Required - The bump texture to set. - **coef** (float32) - Required - The bump coefficient (how much the bump perturbs). ### Returns - `Texture*` - The current bump texture. - `float32` - The current bump coefficient. ``` -------------------------------- ### Initialize D3D9 Engine with Window Handle Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/platform-d3d.md Shows the minimal sequence to initialize and open the RenderWare engine for Windows D3D9. Requires a valid HWND for the window. The render loop is omitted after Engine::start(). ```cpp // Windows D3D9 HWND hwnd = /* your window */; rw::EngineOpenParams params; params.window = hwnd; rw::Engine::init(); rw::Engine::open(¶ms); rw::Engine::start(); // render loop ... ``` -------------------------------- ### Post-build copy checker.dff and create files directory Source: https://github.com/aap/librw/blob/master/tools/lights/CMakeLists.txt Adds a POST_BUILD custom command that creates a files directory next to the lights executable and copies checker.dff from the source directory. ```cmake add_custom_command( TARGET lights POST_BUILD COMMAND "${CMAKE_COMMAND}" -E make_directory "$/files" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/checker.dff" "$" ) ``` -------------------------------- ### get(const Material*) Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/matfx.md Returns the MatFX plugin payload of a material. Provides access to the MatFX struct for further manipulation. ```APIDOC ## get(const Material*) ### Description Returns the MatFX plugin payload of a material. Provides access to the MatFX struct for further manipulation. ### Method Static method ### Signature `static MatFX *get(const Material *m);` ### Parameters - **m** (const Material*) - Required - The material to retrieve the MatFX from. ### Returns MatFX* - Pointer to the MatFX struct associated with the material. ``` -------------------------------- ### registerHAnimPlugin Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/hanim.md Registers the HAnim plugin with the engine, including driver, frame, and animation interpolator registration, and installs streaming hooks. ```APIDOC ## registerHAnimPlugin ### Description Registers the HAnim plugin with the engine, including driver, frame, and animation interpolator registration, and installs streaming hooks. ### Method Free function ### Signature `void registerHAnimPlugin(void)` ### Parameters None ### Returns void ``` -------------------------------- ### Define camera executable target Source: https://github.com/aap/librw/blob/master/tools/camera/CMakeLists.txt Creates the camera executable with WIN32 subsystem, including main.cpp, camexamp.cpp, and viewer.cpp as sources. ```cmake add_executable(camera WIN32 main.cpp camexamp.cpp viewer.cpp ) ``` -------------------------------- ### Env setters/getters Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/matfx.md Set and get environment mapping properties: texture, reference frame, coefficient, and FB alpha usage. ```APIDOC ## Env setters/getters ### Description Set and get environment mapping properties: texture, reference frame, coefficient, and FB alpha usage. ### Methods - `void setEnvTexture(Texture *t);` - `void setEnvFrame(Frame *f);` - `void setEnvCoefficient(float32 coef);` - `void setEnvFBAlpha(bool32 useFBAlpha);` - `Texture *getEnvTexture(void);` - `Frame *getEnvFrame(void);` - `float32 getEnvCoefficient(void);` - `bool32 getEnvFBAlpha(void);` ### Parameters - **t** (Texture*) - Required - The environment texture to set. - **f** (Frame*) - Required - The reference frame for environment coordinates. - **coef** (float32) - Required - The environment coefficient. - **useFBAlpha** (bool32) - Required - Whether to use framebuffer alpha. ### Returns - `Texture*` - The current environment texture. - `Frame*` - The current reference frame. - `float32` - The current environment coefficient. - `bool32` - Whether FB alpha is used. ``` -------------------------------- ### Engine::stop Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/engine.md Stops the engine by destructing plugins and terminating the device. Transitions the engine state from Started to Opened. ```APIDOC ## Engine::stop ### Description Stops the engine by destructing plugins and terminating the device. Transitions the engine state from Started to Opened. ### Method Engine::stop ### Signature ```cpp static void stop(void); ``` ### Errors - Raises `ERR_GENERAL` (and returns) unless state is `Started`. ### Details Destructs all engine and driver plugins, runs `device.system(DEVICETERM, nil, 0)`. Transition: `Started` → `Opened`. ``` -------------------------------- ### Path and file helper declarations Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/base.md Declares makePath, getFileContents, and findPointer. makePath normalizes '/' and '\' separators and on unix calls correctPathCase to match case-insensitively. getFileContents returns a malloc'd buffer via rwNewT. findPointer returns the index of p in list or -1. ```cpp void makePath(char *filename); // normalize '/' '\' separators (+ case-correct on unix) uint8 *getFileContents(const char *name, uint32 *len); // malloc'd buffer via rwNewT int32 findPointer(void *p, void **list, int32 num); // index of p in list, or -1 ``` -------------------------------- ### Quat Source: https://github.com/aap/librw/blob/master/_autodocs/types.md A quaternion type with x, y, z, w components, a static rotation method, and methods for setting, getting the vector part, and rotating. ```APIDOC ## Quat ### Description A quaternion type with x, y, z, w components, a static rotation method, and methods for setting, getting the vector part, and rotating. ### Members - `float32 x` - The x component. - `float32 y` - The y component. - `float32 z` - The z component. - `float32 w` - The w component. ### Methods #### static rotation(float32 angle, const V3d &axis) Creates a quaternion representing a rotation around an axis. #### set(float32 w, float32 x, float32 y, float32 z) Sets the quaternion components. #### V3d vec(void) Returns the vector part (x, y, z) as a V3d. #### Quat *rotate(const V3d *axis, float32 angle, CombineOp op = rw::COMBINEPOSTCONCAT) Rotates the quaternion by the given axis and angle, using the specified combine operation. ### Parameters - `angle` (float32) - Rotation angle in radians. - `axis` (const V3d*) - Rotation axis. - `op` (CombineOp) - Combine operation (default: COMBINEPOSTCONCAT). ``` -------------------------------- ### dmaKick() Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/ps2.md Kicks the DMA transfer to start processing the queued graphics commands. This is a low-level helper for the PS2 real-hardware path. ```APIDOC ## dmaKick() ### Description Kicks the DMA transfer to start processing the queued graphics commands. This is a low-level helper for the PS2 real-hardware path. ### Parameters None. ### Return Value None. ``` -------------------------------- ### Render state setting functions Source: https://github.com/aap/librw/blob/master/_autodocs/api-reference/render.md Functions to set and get render states. SetRenderState packs the value into the pointer form; GetRenderState unpacks it. ```cpp void SetRenderState(int32 state, uint32 value); void SetRenderStatePtr(int32 state, void *value); uint32 GetRenderState(int32 state); void *GetRenderStatePtr(int32 state); ``` -------------------------------- ### Apply platform-specific target settings Source: https://github.com/aap/librw/blob/master/tools/lights/CMakeLists.txt Invokes librw_platform_target on the lights target to apply platform-specific build settings. ```cmake librw_platform_target(lights) ```