codeblocks glfw glew glm 配置

本文详细介绍了如何在CodeBlocks IDE中设置现代OpenGL 3.2及以上版本,包括使用GLFW创建窗口,GLEW加载OpenGL API,以及GLM进行数学运算。教程覆盖了下载、配置和链接这些开源库的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Wednesday, May 8, 2013

Setup Modern OpenGL with GLFW, GLEW and GLM in Codeblocks

Modern OpenGL 3 and above version may be difficult especially for beginner because of  new shaders and buffer object concepts. OpenGL 1.x is simple to understand and to setup the project also which you can find in my previous articles  here. By setting the  GLUT or just by including  gl.h and  glu.h we can acess the OpenGL function because all the API function are determined in compiled time but in modern OpenGL concept is different that all the API function are determined in run time not in compiled time.  Introduction to GLFW,GLEW and GLM
Lets discusses about all this open source library why they are necessary. GLEW (OpenGL Extension Wrangler  will handle the run time loading of the OpenGL API. This will give access to the OpenGL 3.2 and above API functions. It is important because accessing  OpenGL functions isn't as simple as #include <GL/gl.h> unless we want to use an ancient version of OpenGL. In modern OpenGL , the API functions are determined at run time,not compile time.
GLFW (OpenGL Frame Work ) is used to create a window, and receive mouse and keyboard input in a cross-platform way. We can use freeglut as a alternative of GLFW . GLFW is especially design for game. OpenGL does not handle window creation or input, so this must be done with the help of GLFW or other alternatives. 
GLM(OpenGL Mathematics ) is a mathematics libray that handles vectors and metrices. Older versions of OpenGL provided functions like glRotate, glTranslate and glScale which would do some of the mathematics but in modern OpenGL previously mentioned functions do not exist and we have to do by ourselves. GLM will help us to do math.
Setup instruction for GLFW,GLEW and GLM 
Step 1st : Download and Extract all these library 
                GLEW  from here 
                GLFW  from here
                GLM  from here
Step 2nd : Copy header files,library files and dll files to following directories. A. Copy Header Files
                 Copy  glfw3.h, form GLFW library include folder, and  glew.h,glxew.h,wglew.h from GLEW library include folder to the directory  C:\Program Files\CodeBlocks\MinGW\include\GL
Since GLM is header only library copy the whole  glm folder to the directory  C:\Program Files\CodeBlocks\MinGW\include
B. Copy Library Files
                Copy  libglfw3.a and  glfw3dll.a form GLFW library lib-mingw folder and  glew32glew32sglew32mxglew32mxs from GLEW library lib folder to the directory  C:\Program Files\CodeBlocks\MinGW\lib
C. Copy DILL Files
                Copy  glfw3.dll form GLFW library lib-mingw folder, and  glew32.dll , glew32mx.dll from GLEW library bin folder to the directory  C:\Windows\System32
Step 3rd: Change  CodeBlocks linker setting
Open the Codeblocks IDE.
go to menu ->Settings->Compiler options
From there click the Linker setting tab.
From Link libraries box. Click add button and add libraries  glew32.libglew32s.lib, libglfw3.a and  libopengl32.a
All the linker must be link from the directory  C:\Program Files\CodeBlocks\MinGW\lib Note: make sure that glew32s.lib must be top of the list.
Press ok . Now your library is completely setup. You can write modern OpenGL program by creating new empty cpp file. Check weather all libraries are setup successfully or not run the source code from  here(simple modern OpenGL program)
18 comments:
  1. Where do I find "libopengl.a" ?

    ReplyDelete
  2. inside the directory programfiles->codeblocks->Mingw->lib you can find

    Delete
  3. sorry not libopengl.a it is libopengl32.a. I have edited my post.

    Delete
  4. When I download GLFW, I don't get glfw.dll. I get glfw3.dll and so on. In every file there is a 3 at the end. Am I downloading the wrong file or is it just a newer version?

    ReplyDelete
  5. yes it is new version release at june 17,2013.

    Delete
  6. Ok, thanks for the answer. However, when I run the test-code I get loads of errors with GLFW, like "glfwOpenWindowHint was not declared in this scope" and so on. I've followed the instructions carefully, so I don't know what I'm doing wrong.

    Delete
  7. In test-code there is #include so change it to $include and try. If this is not the problem then check wheather your GLFW is 64-bit and glew is 32-bit something like that. I suggest you although you computer is 64-bit use both GLFW and glew 32-bit.

    Delete
  8. In latest GLFW use glfwWindowHint instead glfwOpenWindowHint

    ReplyDelete
  9. I think all of these need updating as their have been many function name and parameter changes.
    That and if the version number of the libraries was known it would help in removing the need to hunt and attempt to figure out what got changed to what in trying to get these samples running.
    Either that or the removal of GLFW from the samples as it is the library causing the most headaches in trying to get these samples to run.
    Thought the best sure fire way of having usable samples with minimal headache would be samples only using the glm Library, 
    as this would keep the dependance and setup simple and without the headache to many libraries that are getting updated constantly.

    ReplyDelete
  10. can you write a tutorial on using GLFW3 with GLew 1.10? The documentation is very vague on setting up a simple window. 
    This site implements GLew 1.10, but it does a bit too much and eats up resources:
    http://blog.gvnott.com/2013/05/18/tutorial-multiple-windows-with-glfw3-and-glew-mx/

    ReplyDelete
  11. i have been trying to get it running for quiet a while, is it possible to rar the whole directory of codeblocks and put it on the newsgroups ... thanks in advance 
    greetings 
    Dave

    ReplyDelete
  12. here(simple modern OpenGL program) program is not running. please help me. the error is given bellow
    ||=== Build: Debug in dsf (compiler: GNU GCC Compiler) ===|
    D:\openGL\dsf\main.cpp||In function 'void Render()':|
    D:\openGL\dsf\main.cpp|125|error: too few arguments to function 'void glfwSwapBuffers(GLFWwindow*)'|
    c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\GL\glfw.h|2209|note: declared here|
    D:\openGL\dsf\main.cpp||In function 'void AppMain()':|
    D:\openGL\dsf\main.cpp|145|error: 'glfwOpenWindowHint' was not declared in this scope|
    D:\openGL\dsf\main.cpp|147|error: 'GLFW_OPENGL_VERSION_MAJOR' was not declared in this scope|
    D:\openGL\dsf\main.cpp|149|error: 'GLFW_OPENGL_VERSION_MINOR' was not declared in this scope|
    D:\openGL\dsf\main.cpp|151|error: 'GLFW_WINDOW_NO_RESIZE' was not declared in this scope|
    D:\openGL\dsf\main.cpp|153|error: 'GLFW_WINDOW' was not declared in this scope|
    D:\openGL\dsf\main.cpp|153|error: 'glfwOpenWindow' was not declared in this scope|
    D:\openGL\dsf\main.cpp|197|error: 'GLFW_OPENED' was not declared in this scope|
    D:\openGL\dsf\main.cpp|197|error: 'glfwGetWindowParam' was not declared in this scope|
    ||=== Build failed: 9 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

    ReplyDelete
  13. Same errors as the above guy ... Probably there are some changes in glfw.h (which in fact is glfw3.h) ...

    ReplyDelete
  14. I have updated the program now such error will not occur.

    ReplyDelete
  15. I did everything exactly as stated,but when i build and run the program ,nothing happens,it does not do anything.
    Do you start with a empty project or a glfw project or something else ?

    ReplyDelete
  16. How is this going to work if you haven't put the location of the 'bin' files in codeblocks-> compiler-> toolchain executables-> additional paths ?

    ReplyDelete
  17. I did add link libraries
    glew32s.lib
    glew32.lib
    libglfw3.a
    libopengl32.a
    and copy lib to CodeBlocks\MinGW\lib
    but i cant build source. error is "cannot find -lglew32s.lib"

    ReplyDelete
  18. ERROR: "glm/glm.hpp no such file or directory"

    ReplyDelete
内容概要:文章详细介绍了电梯门禁(梯控)系统的硬件安装与接线要点。首先强调了梯控板与楼层按键对接的重要性,包括遵循一一对应原则以避免错层、越层问题,允许空层存在以适应实际需求。接着阐述了不同接线方式(COM、NO、NC端口的不同组合)对用户权限的影响,如单层权限用户刷卡直达指定楼层,多层权限用户在特定接线方式下的操作限制。硬件安装方面,强调了无源干触点设计原则以确保电气隔离,防止系统间干扰,以及读卡器接入时的规范要求。文章还介绍了梯控系统的技术原理,如身份验证机制(二维码/IC卡/人脸识别)、消防联动功能(紧急情况下释放所有楼层权限),并指出该系统适用于小区、写字楼等场景,支持机器人乘梯SDK扩展。最后,根据不同场景需求提出了适用的接线方式选择,如严格管控场景下选择4.3接线以实现精准权限控制,限制多层用户手动选层场景下选择4.1接线并配合软件权限设置。; 适合人群:从事电梯安装维护的技术人员、楼宇自动化工程师及相关领域的管理人员。; 使用场景及目标:①指导技术人员正确安装和接线梯控系统,确保系统安全稳定运行;②帮助管理人员了解不同接线方式对用户权限的影响,以便根据实际需求选择合适的配置方案;③提升楼宇安全管理和服务质量,特别是在小区、写字楼等场所的应用。; 其他说明:梯控系统的正确安装和接线不仅关系到系统的正常运作,更直接影响到用户的安全和使用体验。因此,在实际操作中务必严格按照规范执行,同时关注最新的技术发展和应用场景变化,以确保系统始终处于最佳状态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值