[問題] openGL的shader compile問題

看板C_and_CPP作者 (金色小黃花)時間7年前 (2016/12/09 13:38), 7年前編輯推噓3(4115)
留言20則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...) win7 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) glew, glut 問題(Question): 我是c++兼opengl noob, 可能是很蠢的問題 我照這個網址的練習來做 http://blog.csdn.net/cordova/article/details/52495077 這個是以下網址的中文翻譯版, code也在其中 http://ogldev.atspace.co.uk/www/tutorial04/tutorial04.html 但是在編譯時會出現 fatal error C1021: invalid preprocessor command 'version' 中文為無效的前置處理器命令 完全看不懂... 照理說我應該已經指定用opengl去編譯了才對 我在網路上opengl論壇有看到有人有類似的問題(ptt不給縮網址 囧) https://www.opengl.org/discussion_boards/showthread.php/ 181901-version-syntax-will-not-work-on-Visual-Studio-C 但是還是不知道怎麼解... 餵入的資料(Input): 預期的正確結果(Expected Output): 可以編譯過就好QQ 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 如網址 需要額外include的檔案在 https://github.com/triplepointfive/ogldev/tree/master/Include 其中的ogldev_math_3d.h 如果還有需要include的會在 https://github.com/assimp/assimp/tree/master/include/assimp 這邊的檔案中 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.186.245 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1481261901.A.173.html ※ 編輯: goldflower (140.113.186.245), 12/09/2016 13:40:48 ※ 編輯: goldflower (140.113.186.245), 12/09/2016 13:42:01

12/09 17:31, , 1F
呃,你可能不小心把shader.vs或shader.fs拿來compile
12/09 17:31, 1F

12/09 17:50, , 2F
了,因為.vs、.fs檔裡面的第一行是#version 330
12/09 17:50, 2F

12/09 17:50, , 3F
這好像就是這個錯誤所代表的意思 請問具體上要怎麼
12/09 17:50, 3F

12/09 17:50, , 4F
解決呢?
12/09 17:50, 4F

12/09 17:54, , 5F
這2個檔案長得很像C語言,但是其實是GLSL
12/09 17:54, 5F

12/09 18:01, , 6F
想辨法讓Visual Studio把main.cpp當成主程式,也許是
12/09 18:01, 6F

12/09 18:01, , 7F
我其實有把shader object丟到glCompileShader
12/09 18:01, 7F

12/09 18:02, , 8F
因為.vs,.fs裡面也有main()
12/09 18:02, 8F

12/09 18:04, , 9F
先確認一下你 OpenGL render context 是不是拿對版本
12/09 18:04, 9F

12/09 18:24, , 10F
試試把.vs,.fs從solution explorer移除(但不刪除)
12/09 18:24, 10F

12/09 20:34, , 11F
12/09 20:34, 11F

12/09 20:35, , 13F
draw triangle就開始談shader了
12/09 20:35, 13F

12/09 20:35, , 14F
Hello Triangle
12/09 20:35, 14F

12/09 20:38, , 15F
樓主那個網頁太精簡 不好學
12/09 20:38, 15F

12/09 20:39, , 16F
learnopengl.com有完整的code 基本上裡面的內容
12/09 20:39, 16F

12/09 20:39, , 17F
算是談到進階甚至接近專業
12/09 20:39, 17F

12/09 20:40, , 18F
glut也是比較舊的 新的glfw比較現代
12/09 20:40, 18F

12/09 20:42, , 19F
最重要的事 你程式碼沒貼上來當大家有水晶球
12/09 20:42, 19F

12/10 00:39, , 20F
好的我試試看@@ 感謝
12/10 00:39, 20F
文章代碼(AID): #1OIaDD5p (C_and_CPP)