glBegin在OpenGl3.3之后还能使用吗
时间: 2023-06-10 13:07:25 浏览: 59
在OpenGL 3.3及之后的版本中,glBegin和glEnd已经被弃用,不能直接使用了。这是因为它们是立即渲染模式的一部分,而现代的OpenGL版本已经移向了基于着色器的渲染模式。在新版本的OpenGL中,你需要使用顶点缓冲对象(VBO)和顶点数组对象(VAO)来代替glBegin和glEnd。这些对象可以更好地管理和处理顶点数据,提高渲染效率。如果你想在OpenGL 3.3及以上版本中使用立即渲染模式,你可以使用GL_POINTS、GL_LINES、GL_TRIANGLES等绘制原语,但需要注意,这些函数也已经被标记为过时。建议使用现代OpenGL的渲染方式。
相关问题
Qt OpenGL 3.3显示列表代码
好的,下面是一个简单的使用Qt和OpenGL 3.3创建和使用显示列表的代码示例:
```c++
// 在头文件中定义显示列表的ID
GLuint m_displayListID;
// 在初始化函数中创建显示列表
void initializeGL()
{
// 生成一个唯一的ID作为显示列表的标识符
m_displayListID = glGenLists(1);
// 开始记录显示列表
glNewList(m_displayListID, GL_COMPILE);
// 在此添加需要打包的OpenGL命令序列
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
// 结束记录显示列表
glEndList();
}
// 在绘制函数中调用显示列表
void paintGL()
{
// 清空屏幕
glClear(GL_COLOR_BUFFER_BIT);
// 调用显示列表
glCallList(m_displayListID);
// 刷新窗口
glFlush();
}
```
以上就是一个简单的使用Qt和OpenGL 3.3创建和使用显示列表的代码示例,希望对您有所帮助。需要注意的是,这只是一个简单的示例,实际应用中需要根据具体情况进行修改。
undefined reference to `glad_glBegin' opengl4
This error occurs when the linker is unable to find the definition of the function `glad_glBegin` in your code.
To resolve this issue, you need to ensure that you have properly linked the OpenGL library and that your code includes the necessary headers. Here are some steps you can follow:
1. Make sure that you have included the appropriate OpenGL headers in your code. For example, you may need to include the following header:
```c++
#include <glad/glad.h>
```
2. Ensure that you have properly linked the OpenGL library. You can do this by adding the following line to your CMakeLists.txt file (or equivalent build system file):
```cmake
target_link_libraries(your_project_name PRIVATE opengl32)
```
Note that the library name may be different depending on your platform.
3. Make sure that you have initialized the GLAD library before calling any OpenGL functions. You should call `gladLoadGL()` after creating an OpenGL context. Here's an example:
```c++
if (!gladLoadGL()) {
std::cerr << "Failed to initialize GLAD" << std::endl;
exit(EXIT_FAILURE);
}
```
4. Check that you are using the correct function name. In this case, `glad_glBegin` should be `glBegin`.
By following these steps, you should be able to resolve the undefined reference to `glad_glBegin` error and successfully compile your code.