openFrameworks Website Source and Documentation

repository·master·Indexed 41 days ago

https://github.com/openframeworks/ofsite

Content and source code for the official openFrameworks website, including tutorials, API documentation, and setup guides. Includes instructions for building the site locally using Nikola and AsciiDoc, as well as detailed guides for configuring openFrameworks for Android development using Eclipse and Android Studio (specifically NDK r15c for version 0.10.0).

Tokens
169K
Snippets
578
Records
902
Agent score
97%

What's inside openFrameworks

  1. What is openFrameworks?

    master

    openFrameworks (oF) is an open-source C++ toolkit designed for creative coding and experimentation. It acts as a software framework that wraps together several specialized libraries into a single, consistent interface. This allows developers to focus on high-level creative logic rather than the low-level complexities of individual libraries.

    Key characteristics:

    • Language: It uses C++.
    • Framework Model: Unlike a library where you control the flow, oF uses Inversion of Control. The framework manages the infrastructure and event loops, while your code responds to events and defines the application's specific behavior.
    • Cross-Platform: Supports Windows, OSX, Linux, iOS, and Android.
    • IDE Support: Works with XCode, Code::Blocks, Visual Studio, and Eclipse.
  2. Use ofLog for text output

    master

    The ofLog class provides an interface for writing text output from your application. It is a more powerful alternative to cout or printf, allowing you to filter messages by priority (log levels) and redirect output to the console or a file.

    Logging is useful for debugging variable states or recording logs to a file to diagnose crashes after a program terminates.

  3. Why use openFrameworks for creative coding?

    master

    openFrameworks (oF) is a generic tool designed for the intersection of different disciplines. Key advantages include:

    • Portability: Code can run on macOS, Linux, and Windows. With adjustments, it can be ported to Android, iOS, and even the web (since version 0.9).
    • Versatility: A single tool covers 2D/3D graphics, computer vision, sound/music computing, and deep learning.
    • Hardware Support: Extensive support for various hardware through a wide range of community-driven addons.
    • Community: Access to a large, active community for support.
  4. Overview of openFrameworks class types

    master

    openFrameworks organizes its functionality into several distinct class categories:

    • Utility Classes: Classes that perform actions (e.g., ofVideoPlayer, ofSoundPlayer). They often use the setup/update/draw pattern and typically use shallow copying.
    • Data Containers: Classes that hold data (e.g., ofPixels, ofBuffer). They use an allocate/loadData pattern and use deep copying.
    • GL Data Containers: Specialized containers for GPU resources (e.g., ofTexture, ofFbo). They use an allocate/loadData pattern but use shallow copying for performance.
    • Data Types: Lightweight classes representing mathematical or geometric primitives (e.g., ofRectangle, ofVec3f, ofMatrix4x4).
    • GL Utility Classes: Classes that manage GL state or objects (e.g., ofShader, ofLight) which behave similarly to standard utility classes.
  5. What is ofVbo and how does it work?

    master

    An ofVbo (Vertex Buffer Object) allows you to store geometry data—such as vertices, normals, colors, and texture coordinates—directly on the graphics card. This enables non-immediate mode rendering, which is significantly more efficient for drawing the same geometry multiple times because you avoid re-uploading data to the GPU every frame.

    Key Concepts

    • Data Properties: Each attribute (vertices, texCoords, normals, colors) can be configured as either static (data won't change after initial load) or dynamic (data will be updated frequently).
    • Drawing Modes: You must provide vertices in an order that matches your chosen OpenGL drawing mode (e.g., GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP). Because of how vertices are connected (winding), you may need to provide more vertices than the literal count of points in a shape (e.g., a cube requires 18 vertices in certain modes rather than 8).
    • Abstraction: For complex geometry where managing vertex order and drawing modes is difficult, use ofMesh, which acts as an abstraction layer over VBOs to manage draw order automatically.
  6. What is ofVec3f?

    master

    ofVec3f is a class used to store and manipulate three-dimensional vectors. It is essential for representing 3D properties such as position, velocity, or acceleration in space. The class provides three member variables, x, y, and z, to store these components.

    Note on Terminology: In C++, a std::vector refers to a dynamically sizeable array. In the context of ofVec3f,

    ofVec3f v1;
    v1.set(10, 50, 80); // v1.x is 10, v1.y is 50, v1.z is 80
  7. What is ofGLProgrammableRenderer and when to use it?

    master

    The ofGLProgrammableRenderer is a specialized renderer designed to support modern OpenGL (3+) and OpenGL ES (GLES). This makes it essential for running openFrameworks on mobile devices (iOS, Android) or ARM-based Linux systems like the Raspberry Pi.

    Key Features:

    • Compatibility: Supports both newer OpenGL versions and GLES.
    • Seamless Transition: You can use the same methods for drawing, meshes, and textures as the older direct pipeline.
    • Automatic Shaders: It automatically creates and uploads default shaders to the GPU upon application startup.
    • Shader Parameters: It provides additional parameters automatically passed to shader programs, which you can leverage when writing custom GLSL shaders.

    Note on GLSL: When moving from the older pipeline to the programmable renderer, the most significant change you will encounter is the GLSL shader syntax, which differs between older and newer OpenGL implementations.

  8. What is ofMesh and how does it work?

    master

    An ofMesh is an abstraction layer for managing 3D geometry. It represents a collection of vertices in 3D space, along with associated properties like normals, colors, and texture coordinates.

    Instead of manually managing the complex 'winding' and connection orders required by the OpenGL rendering pipeline (where you might need multiple vertices at the same location to form a shape like a cube), ofMesh manages the draw order and vertex connections for you. This makes working with complex geometry significantly more efficient and less error-prone.

    ofMesh mesh;
    // Add vertices and properties
    mesh.addVertex(ofPoint(x, y, z));
    mesh.addColor(ofColor(255, 0, 0));
    mesh.addNormal(ofVec3f(0, 1, 0));
    
    // Define how vertices connect using indices
    mesh.addIndex(0);
    mesh.addIndex(1);
    mesh.addIndex(2);
  9. What is a std::map and when to use it

    master

    A std::map is a C++ container that stores elements as key-value pairs, where each key is unique and used to sort and identify the associated value.

    Unlike a std::vector, where you access elements by integer indices that can become invalid if the vector is reordered, a map allows you to access data using meaningful, human-readable keys (like std::string). This is particularly useful for managing large objects like textures or images, as the key remains a stable way to retrieve the object regardless of other insertions or deletions.

    // Instead of managing indices in a vector:
    // vector<ofTexture> images;
    // int portlandIndex = 0;
    
    // Use a map for stable, named access:
    std::map<std::string, ofTexture> images;
    images["Portland"] = myTexture;
    images["Portland"].draw();
  10. What is an ofFbo and how is it used?

    master

    An ofFbo (Frame Buffer Object) is a container for textures and an optional depth buffer. Conceptually, it acts as an off-screen renderer. You can draw 2D or 3D objects, camera views, or video frames into an ofFbo, and then retrieve the resulting texture to use in a shader or draw it directly to the screen.

    ofFbo objects are excellent for performing multiple shader passes (multi-pass rendering) by using the output of one pass as a texture input for the next.

  11. What is a std::multimap?

    master

    A std::multimap is similar to a std::map, but it allows multiple elements to share the same key.

    Use std::map when keys must be unique (e.g., a unique ID for a texture). Use std::multimap when you need to associate multiple values with a single key (e.g., a list of temperatures recorded for the same city name).

    std::multimap<std::string, int> coldestCities;
    // Multiple entries with the same key "moskow" are allowed
    coldestCities.insert(std::make_pair("moskow", 2015));
    coldestCities.insert(std::make_pair("moskow", 2013));