Exemple #1
0
void Adafruit_NeoPixel::show() {

    initializeSdl();

    for (int n = 0; n < numberOfPixels; n++) {
        EmuPixel& epix = emuPixels[n];

        uint32_t rgb = pixels[n];
        int r = rgb >> 16;
        int g = rgb >> 8 & 0xff;
        int b = rgb & 0xff;

        SDL_Rect rect;
        rect.x = epix.x;
        rect.y = epix.y;
        rect.w = epix.width;
        rect.h = epix.height;

        SDL_FillRect(
            screenSurface,
            &rect,
            SDL_MapRGB(screenSurface->format,r,g,b)
        );

    } // for pixels

    SDL_UpdateWindowSurface(window);
    quitOnKey();

} // show()
int main(int argc, char *argv[])
{
    if (initializeSdl()) {
        // Exercise:  Without the depth test, which primitive is on top?
        glEnable(GL_DEPTH_TEST);

#if USE_PROJECTION_MATRIX
        glMatrixMode(GL_PROJECTION);
        GLdouble ratio = 640.0f / 480.0f;
        glOrtho(-ratio, ratio, -1, 1, -1, 1);
#endif

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // With no projection matrix, these are window coordinates,
        // which are left-handed.  (.5 is farther away than 0) The projection
        // matrices generated by the gl functions have a negative z factor
        // (see https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml)
        // which effectively gives us a right-handed coordinate system
        // (.5 is closer than 0)
        drawSquareAt(0, 0, 0);
        drawSquareAt(0.5, 0.5, 0.5);

        SDL_GL_SwapBuffers();
        SDL_Delay(3000);
        SDL_Quit();
    }
    return 0;
}
int main(int argc, char *argv[])
{
    if (initializeSdl()) {
        // Tell GL what matrix we want to modify
        glMatrixMode(GL_PROJECTION);

        // Orthographic projection, which ignores depth.
        GLdouble ratio = 640.0f / 480.0f;
        glOrtho(-ratio, ratio, -1, 1, -1, 1);

        glClear(GL_COLOR_BUFFER_BIT);
        drawSquare();

        SDL_GL_SwapBuffers();
        SDL_Delay(2000);
        SDL_Quit();
    }
    return 0;
}