Skip to content

Lightnet/libretro_core_triangle_glew

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libretro GL Triangle Core

License: MIT

This project is licensed under the MIT License. See LICENSE for details.

Information:

A sample Libretro core demonstrating OpenGL rendering of a rotating RGB triangle with a red background. This project is designed as a minimal example for developers learning to create contentless Libretro cores using OpenGL Core 3.3. It is tested with RetroArch 1.21.0 on Windows.

Features

  • Renders a rotating RGB triangle (red, green, blue vertices) on a red background.
  • Uses OpenGL Core 3.3 with GLEW for function loading.
  • Contentless core (no ROM or content required).
  • Configured for 800x600 resolution with a 4:3 aspect ratio.

Prerequisites

  • Operating System: Windows 10/11 (64-bit).
  • Compiler: Visual Studio 2022 with C++ Desktop Development workload.
  • CMake: Version 3.20 or higher.
  • RetroArch: Version 1.21.0 or later, installed at D:\dev\RetroArch-Win64.
  • Git: For cloning dependencies.

Dependencies

  • GLEW: OpenGL Extension Wrangler Library (fetched via CMake).
  • linmath.h: Lightweight math library for matrix operations (fetched via CMake).

Building the Core

Step 1: Clone the Repository

git clone https://github.com/Lightnet/libretro_core_triangle_glew.git

Step 2: Configure and Build

bat

build.bat

Current set to Debug to log console.

Step 4: RetroArch

Download RetroArch binary for testing in case of fail open application.

Run RetroArch to set up files and folders.

  • Copy build\Debug\triangle_libretro.dll to ''\RetroArch-Win64\cores.

Step 3: Run the Core

  1. Launch RetroArch with verbose logging:

powershell

cd D:\dev\RetroArch-Win64
.\retroarch.exe -v > log.txt 2>&1
  1. In RetroArch:

    • Go to Main Menu > Load Core > Triangle Core.
    • Select Start Core.
  2. Verify:

    • A rotating RGB triangle with a red background appears.

Project Structure

  • src/main.c: Core implementation, handling Libretro lifecycle and OpenGL rendering.
  • build/_deps/linmath-src/linmath.h: Matrix math library.
  • build/_deps/glew-src/: GLEW library for OpenGL extensions.
  • CMakeLists.txt: CMake configuration for building the core.

Notes on Libretro Lifecycle

  • SET_HW_RENDER Placement:

    • This core places SET_HW_RENDER in retro_init instead of the standard retro_set_environment. This works with RetroArch 1.21.0 for contentless cores but may not be compatible with other frontends or versions.
    • Testing showed that SET_HW_RENDER in retro_set_environment caused [libretro] Failed to set HW render, likely due to lifecycle differences for contentless cores.
  • Contentless Core:

    • The core uses RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME to run without content, simplifying retro_load_game.
    • Setting auto_run_contentless_cores = false prevents RetroArch from running a dummy core prematurely.

Troubleshooting

Shader Pass Issue

If [INFO] [slang]: Building pass #0 (N/A) appears in log.txt:

  1. Verify video_shader_enable = false and video_shader = "" in retroarch.cfg.
  2. Check D:\dev\RetroArch-Win64\shaders for .slangp files and remove them.
  3. In RetroArch, ensure Settings > Video > Shaders > Load Shader Preset is None.

Failed HW Render

If [libretro] Failed to set HW render occurs:

  • Keep SET_HW_RENDER in retro_init (current setup).
  • Avoid moving it to retro_set_environment unless testing with other frontends.

Debugging

To debug the core:

  1. Open build\my_libretro_core.sln in Visual Studio 2022.
  2. Set triangle_core as the startup project.
  3. Configure debugging:
    • Command: D:\dev\RetroArch-Win64\retroarch.exe
    • Arguments: -v
    • Working Directory: D:\dev\RetroArch-Win64
  4. Set breakpoints in retro_init, retro_load_game, or retro_run.
  5. Run in Debug mode (F5) to inspect the lifecycle or OpenGL errors.

Future Improvements

  • Add input handling (e.g., keyboard controls to adjust triangle rotation).
  • Support additional OpenGL features (e.g., textures, lighting).
  • Test with other Libretro frontends to validate retro_init vs. retro_set_environment.
  • Optimize shaders or add more complex geometry.

Acknowledgments

About

Simple libretro core render triangle 3d test with opengl.

Topics

Resources

Stars

Watchers

Forks