Ejemplo n.º 1
0
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            const int screenWidth  = 800;
            const int screenHeight = 450;

            InitWindow(screenWidth, screenHeight, "raylib [text] example - font filters");

            string msg = "Loaded Font";

            // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)

            // TTF Font loading with custom generation parameters
            Font font = LoadFontEx("resources/KAISG.ttf", 96, null, 0);

            // Generate mipmap levels to use trilinear filtering
            // NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
            GenTextureMipmaps(ref font.texture);

            float   fontSize     = font.baseSize;
            Vector2 fontPosition = new Vector2(40, screenHeight / 2 - 80);
            Vector2 textSize     = new Vector2(0.0f, 0.0f);

            // Setup texture scaling filter
            SetTextureFilter(font.texture, FILTER_POINT);
            TextureFilterMode currentFontFilter = FILTER_POINT;

            SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
            //--------------------------------------------------------------------------------------

            // Main game loop
            while (!WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                fontSize += GetMouseWheelMove() * 4.0f;

                // Choose font texture filter method
                if (IsKeyPressed(KEY_ONE))
                {
                    SetTextureFilter(font.texture, FILTER_POINT);
                    currentFontFilter = FILTER_POINT;
                }
                else if (IsKeyPressed(KEY_TWO))
                {
                    SetTextureFilter(font.texture, FILTER_BILINEAR);
                    currentFontFilter = FILTER_BILINEAR;
                }
                else if (IsKeyPressed(KEY_THREE))
                {
                    // NOTE: Trilinear filter won't be noticed on 2D drawing
                    SetTextureFilter(font.texture, FILTER_TRILINEAR);
                    currentFontFilter = FILTER_TRILINEAR;
                }

                textSize = MeasureTextEx(font, msg, fontSize, 0);

                if (IsKeyDown(KEY_LEFT))
                {
                    fontPosition.X -= 10;
                }
                else if (IsKeyDown(KEY_RIGHT))
                {
                    fontPosition.X += 10;
                }

                // Load a dropped TTF file dynamically (at current fontSize)
                if (IsFileDropped())
                {
                    int      count        = 0;
                    string[] droppedFiles = Utils.MarshalDroppedFiles(ref count);

                    // NOTE: We only support first ttf file dropped
                    if (IsFileExtension(droppedFiles[0], ".ttf"))
                    {
                        UnloadFont(font);
                        font = LoadFontEx(droppedFiles[0], (int)fontSize, null, 0);
                    }
                    ClearDroppedFiles();
                }
                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                BeginDrawing();
                ClearBackground(RAYWHITE);

                DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY);
                DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY);
                DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY);
                DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY);

                DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK);

                DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY);
                DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY);

                if (currentFontFilter == FILTER_POINT)
                {
                    DrawText("POINT", 570, 400, 20, BLACK);
                }
                else if (currentFontFilter == FILTER_POINT)
                {
                    DrawText("BILINEAR", 570, 400, 20, BLACK);
                }
                else if (currentFontFilter == FILTER_TRILINEAR)
                {
                    DrawText("TRILINEAR", 570, 400, 20, BLACK);
                }

                EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            UnloadFont(font);           // Font unloading
            CloseWindow();              // Close window and OpenGL context
            //--------------------------------------------------------------------------------------

            return(0);
        }
        public unsafe static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            const int screenWidth = 800;
            const int screenHeight = 450;

            InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");

            // Define the camera to look into our 3d world
            Camera3D camera = new Camera3D(new Vector3(16.0f, 14.0f, 16.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), 45.0f, 0);

            Image image = LoadImage("resources/cubicmap.png");      // Load cubicmap image (RAM)
            Texture2D cubicmap = LoadTextureFromImage(image);       // Convert image to texture to display (VRAM)

            Mesh mesh = GenMeshCubicmap(image, new Vector3(1.0f, 1.0f, 1.0f));
            Model model = LoadModelFromMesh(mesh);

            // NOTE: By default each cube is mapped to one part of texture atlas
            Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");    // Load map texture

            // Set map diffuse texture
            Utils.SetMaterialTexture(ref model, 0, MAP_ALBEDO, ref texture);

            Vector3 mapPosition = new Vector3(-16.0f, 0.0f, -8.0f);          // Set model position

            UnloadImage(image);     // Unload cubesmap image from RAM, already uploaded to VRAM

            SetCameraMode(camera, CAMERA_ORBITAL);  // Set an orbital camera mode

            SetTargetFPS(60);                       // Set our game to run at 60 frames-per-second
            //--------------------------------------------------------------------------------------

            // Main game loop
            while (!WindowShouldClose())            // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                UpdateCamera(ref camera);              // Update camera
                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                BeginDrawing();

                ClearBackground(RAYWHITE);

                BeginMode3D(camera);

                DrawModel(model, mapPosition, 1.0f, WHITE);

                EndMode3D();

                DrawTextureEx(cubicmap, new Vector2(screenWidth - cubicmap.width * 4 - 20, 20), 0.0f, 4.0f, WHITE);
                DrawRectangleLines(screenWidth - cubicmap.width * 4 - 20, 20, cubicmap.width * 4, cubicmap.height * 4, GREEN);

                DrawText("cubicmap image used to", 658, 90, 10, GRAY);
                DrawText("generate map 3d model", 658, 104, 10, GRAY);

                DrawFPS(10, 10);

                EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            UnloadTexture(cubicmap);    // Unload cubicmap texture
            UnloadTexture(texture);     // Unload map texture
            UnloadModel(model);         // Unload map model

            CloseWindow();              // Close window and OpenGL context
            //--------------------------------------------------------------------------------------

            return 0;
        }