SurajSharma90 / SFML_RPG

RPG game made in SFML using C++
191 stars 36 forks source link

Issue with shader #10

Open pbaret opened 1 year ago

pbaret commented 1 year ago

Hey, I just found your video series and the source code for the RPG, I manage to build it and found a lot of interesting stuff so first of all thank you! However I have a problem when I click "New Game", it crashes with a shader error in the console:

Failed to compile vertex shader:
WARNING: 0:1: '' :  #version directive missing
WARNING: 0:1: 'varying out' : symbol not available in current GLSL version
ERROR: 0:1: 'varying out' :  supported in fragment shaders only

ERROR::GAMESTATE::COULD NOT LOAD SHADER.

Any idea what is the problem? and maybe a hint on how to fix or work around this?

I know C++ very well, just started SFML (built 2.5.1 from source on Windows with MinGW 12.2.0, I do have a NVidia GPU on the machine) but I have very limited knowledge on shaders.

blrbrb commented 1 year ago

When you create the RenderWindow, are you setting the gl version? Are you also specifying the version with the #version directive? I had the same issue awhile back. Apparently, large portions of the SFML graphics module are written using depreciated parts of the OpenGL library and won't have foward compatibility. I fixed the issue by simply removing the depreciated part, "varying". Hope you find a solution soon! :)

pbaret commented 1 year ago

No I didn't make any modifications of the original code when experiencing the crash. I was just using my own toolchain to build the project : SFML and Compiler I have on my PC and CMAKE :

I had to build a CMakeLists.txt though :

project(SFML_RPG)

cmake_minimum_required(VERSION 3.13.0)

add_executable(SFML_RPG)

find_package(SFML 2.5 COMPONENTS system window graphics network audio main REQUIRED)

target_sources(SFML_RPG PRIVATE
    src/AIComponent.cpp
    src/AttributeComponent.cpp
    src/DefaultEditorMode.cpp
    src/EnemyEditorMode.cpp
    src/Game.cpp
    src/HitboxComponent.cpp
    src/MeleeWeapon.cpp
    src/PlayerGUI.cpp
    src/RegularTile.cpp
    src/Sword.cpp
    src/TileMap.cpp
    src/stdafx.cpp
    src/AIFollow.cpp
    src/Bird1.cpp
    src/EditorMode.cpp
    src/EnemySpawnerTile.cpp
    src/GameState.cpp
    src/Inventory.cpp
    src/MovementComponent.cpp
    src/PlayerGUITabs.cpp
    src/SettingsState.cpp
    src/Tab.cpp
    src/VectorMath.cpp
    src/AIOption.cpp
    src/Bow.cpp
    src/EditorState.cpp
    src/EnemySystem.cpp
    src/GraphicsSettings.cpp
    src/Item.cpp
    src/PauseMenu.cpp
    src/RangedWeapon.cpp
    src/SkillComponent.cpp
    src/TextTagSystem.cpp
    src/Weapon.cpp
    src/AnimationComponent.cpp
    src/CharacterTab.cpp
    src/Enemy.cpp
    src/Entity.cpp
    src/Gui.cpp
    src/MainMenuState.cpp
    src/Player.cpp
    src/Rat.cpp
    src/State.cpp
    src/Tile.cpp
    src/main.cpp
)

target_include_directories(SFML_RPG PRIVATE 
    inc/
    ${SFML_DIR}/../../../include        # required otherwise can't find SFML headers
)

target_link_directories(SFML_RPG PRIVATE
    ${SFML_DIR}/../..       # required otherwise can't find SFML libraries when linking
)

target_compile_options(SFML_RPG PUBLIC -Wconversion) 

target_link_libraries (SFML_RPG sfml-audio sfml-graphics sfml-network sfml-system sfml-window)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Shader/fragment_shader.frag ${CMAKE_CURRENT_BINARY_DIR}/ COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Shader/vertex_shader.vert ${CMAKE_CURRENT_BINARY_DIR}/ COPYONLY)