我在哪里可以学习如何使用 C++ 与显卡连接?

发布于 2024-10-02 11:00:56 字数 250 浏览 9 评论 0原文

我现在正在学习 C++,我想开始与显卡交互并学习 3D 图形的基础知识。我在我的书中或互联网查询中都没有找到它,而且我实际上完全不知道从哪里开始。 C++代码编译后可以在显卡上运行吗?我知道我通过 OpenGL 访问 GPU 处理,但我不清楚这是否只是一个通过 C++(可能还有其他语言)访问以将函数传递给 GPU 的库,或者它是否特定于GLSL。 那么什么是 OpenGL,如何将它与 C++ 结合使用,以便将处理传递给 GPU?还有其他更直接或更灵活的方式来使用 C++ 和显卡吗?

I'm learning c++ right now and I'd like to start interfacing with a graphics card and play with the basics of 3d graphics. I haven't found it in my book or in internet queries, and I actually have absolutely no idea where to start with this. Can c++ code run on a graphics card once it is compiled? I understand that I access GPU processing through OpenGL but I'm unclear whether this is just a library for accessing through c++ (and probably other languages) to pass functions to the GPU, or if it is specific to GLSL.
So what is OpenGL, and how can I use it in conjunction with c++ in order to pass processing to the GPU? Are there other more direct or flexible ways to work with C++ and a graphics card?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

最佳男配角 2024-10-09 11:00:56

OpenGL 是一个库。您的 C++ 代码会编译为机器代码(针对您的 CPU,而不是 GPU),并调用 OpenGL 函数,该函数将数据发送到您的显卡 (GPU)。显卡解释该数据,并使用它来执行您要求它执行的任何操作。 GPU 不运行您的任何 C++ 代码。

GLSL(OpenGL 着色语言)是一种用于指示 GPU 着色器执行操作的语言。请注意,这个名称有点用词不当,因为如今用着色语言编写的代码所做的不仅仅是着色。通常,您将像编写 C++ 代码一样编写 GLSL 代码,然后使用 OpenGL 调用来编译 GLSL 代码,然后使用更多 OpenGL 调用来指示 CPU 使用着色器程序。


CPU

C++代码调用OpenGL函数调用图形驱动程序代码,后者通过硬件将指令传输到GPU

GPU

解释从图形驱动程序接收到的硬件信号以运行其自己的内部程序。这可能包括已编译的 GLSL 程序,这些程序也以相同的方式从 CPU 发送。


注意:您可以将“Open GL 函数”替换为“DirectX 函数”,将“GLSL”替换为其他着色语言,图表是相同的。

OpenGL is a library. Your C++ code, which compiles into machine code (for your CPU, not GPU), calls OpenGL functions, which send data to your graphics card (GPU). The graphics card interprets that data, and uses it to do whatever you've asked it to do. The GPU does not run any of your C++ code.

GLSL (OpenGL Shading Language) is a language used to instruct what the GPU's shaders do. Note that the name is a bit of a misnomer, because code written in shading languages do a lot more than shading nowadays. Typically, you will write your GLSL code much like you write your C++ code, then use OpenGL calls to compile the GLSL code, and then use more OpenGL calls to instruct the CPU to use the shader programs.


CPU

C++ code calls OpenGL functions calls Graphics driver code, which transmits instructions to the GPU through hardware.

GPU

Interprets hardware signals received from the graphics driver to run its own internal programs. This may include compiled GLSL programs, which are also sent from CPU in the same way.


Note: You can replace "Open GL functions" with "DirectX functions" and "GLSL" with another shading language and the diagram is the same.

梦一生花开无言 2024-10-09 11:00:56

OpenGL 和 DirectX 为您完成与显卡的接口。

您可以自己编写低级代码,但我建议首先了解基础知识。

完成此操作后,您可以考虑自己编写图形驱动程序,但不要指望能够击败卡制造商开发团队的性能。

OpenGL and DirectX do the interfacing to the graphics card for you.

You can write the low level code yourself, but I'd recommend getting an understanding of the basics first.

Once you've done that you could look at writing the graphics drivers yourself, but don't expect to beat the performance of the card manufacturers teams of developers.

笨笨の傻瓜 2024-10-09 11:00:56

Opengl NeHe 的权威之地。这里的教程将帮助您了解基础知识。

The definitive place for Opengl NeHe. The tutorials here will get you started with the basics.

梦巷 2024-10-09 11:00:56

简而言之,OpenGL 是一个与显卡驱动程序通信的库。您可以在 C++ 中调用 OpenGL 函数,从而将命令发送到 GPU 进行处理。您的 C++ 代码始终在 CPU 上运行,包括所有 OpenGL 库调用,但这些调用会转换为显卡驱动程序可以理解的命令。

过去,GPU 具有固定功能管道,OpenGL 充当状态机,您可以在其中启用和禁用某些功能,例如指定光源的位置或如何将某些图像映射到对象。 OpenGL 仍然是一个状态机,但通过可编程着色器,您可以用类似 C 的语言编写程序( GLSL)并使用OpenGL函数指示驱动程序编译和链接程序并在GPU上执行它们。

OpenGL SuperBible 是开始了解有关 OpenGL 的更多信息的好地方。最新版本不涵盖旧的固定功能管道(您无法编写着色器)并且需要一个相当不错的视频卡。

Simply put, OpenGL is a library that communicates with your graphic card's driver. You call OpenGL functions in C++ which result in commands being sent to the GPU for processing. Your C++ code is always run on the CPU, including all your OpenGL library calls, but the calls are translated to commands that are understood by the graphic card driver.

In the past the GPU had a fixed-function pipeline and OpenGL acted as a state machine where you to enable and disable certain functionality such as specifying the position of a light source or how some image should be mapped to an object. OpenGL is still a state machine, but with programmable shaders you write programs in a C-like language (GLSL) and use OpenGL functions to instruct the driver to compile and link the programs and execute them on the GPU.

A good place to start learning more about OpenGL is OpenGL SuperBible. The latest version doesn't cover the old fixed-function pipelines (where you couldn't write shaders) and requires a somewhat decent video card.

三生殊途 2024-10-09 11:00:56

首先,我建议您使用 GLUT(GL 实用工具包)API。在这里查找... http://www.opengl.org/resources/libraries/ glut/

我认为这是使用 openGL 开始图形编程的最佳方式。

To start off, I would recommend that you use the GLUT (GL Utility Toolkit) API. Look it up over here... http://www.opengl.org/resources/libraries/glut/

I think it is the best way to start graphics programming using openGL.

瞎闹 2024-10-09 11:00:56

您是否有兴趣使用 GPU 来...

图形:您有两个接口:OpenGL(多平台)和 Direct3D (Windows),几乎所有 GPU 驱动程序都支持这两个接口。

计算:最常见的 ATM 接口是 NVidia 的 CUDA(仅适用于 GeForce 卡)。还有 OpenCL(应该在所有地方都受支持,但我不确定 GeForce 上的当前状态;在 ATI 上一切正常)以及 AMD/ATI 的一些我不熟悉的专有解决方案。

选择您喜欢的任何内容并开始学习,网上有很多针对上述内容的示例和教程。

Are you interested in using GPU for...

Graphics: You have two interfaces, OpenGL (multiplatform) and Direct3D (Windows), both supported by virtually all GPU drivers.

Calculations: The most common interface ATM is CUDA by NVidia (only for GeForce cards). There's also OpenCL (should be supported everywhere, but I'm not sure about current state on GeForces; all OK on ATI) and some proprietary solutions by AMD/ATI with which I'm not familiar with.

Pick whatever you fancy and start learning it, there's a lot of examples and tutorials for any of the above to be found online.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文