使用OpenGl核心中的单个像素画一条线 [英] Drawing a line using individual pixels in OpenGl core

查看:290
本文介绍了使用OpenGl核心中的单个像素画一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在OpenGl中实现线条绘制算法.我从 learnopengl 了解了使用OpenGl的基础知识.在线条绘制算法中,我需要设置单个像素本身.我不了解如何在像素级别使用OpenGl.我尝试在opengl中搜索实现布雷森汉姆的行算法,到处都是实现使用功能 glDrawPixels 的地方,而该功能在OpenGl3.3中不受支持.我在OpenGl3.3中缺少什么吗?

I am trying to implement a line drawing algorithm in OpenGl. I have learnt the basics of using OpenGl from learnopengl. In the line drawing algorithm I need to set the individual pixel itself. I don't understand how to use the OpenGl at pixel level. I tried searching for the implementation bresenham's line algorithm in opengl, everywhere the implementation uses the function glDrawPixels which is not supported in OpenGl3.3. Is there anything that I'm missing in OpenGl3.3?

推荐答案

OpenGL的重点是使用可以为您进行栅格化的硬件.如果您要自己进行光栅化,只需将像素写入分配的内存中,就完全不需要OpenGL了.无论如何,它不会为您做任何事情.

The point of OpenGL is to use hardware that will do rasterization for you. If you're doing rasterization yourself, just write pixels into memory you allocate yourself, you don't need OpenGL at all; it isn't going to be doing anything for you anyway.

要显示图像,可以将图像上载到纹理(glTexImage2D/glTexSubImage2D),然后绘制一个映射有该纹理的四边形.或使用操作系统的窗口/UI例程在窗口上绘制图像,这可能会更容易.

To display your image, you can upload your image to a texture (glTexImage2D/glTexSubImage2D), and then draw a quad with that texture mapped to it. Or use your OS's window/UI routines to paint the image on the window, which will probably be easier.

如果您真的想使用OpenGL一张一张地绘制单个像素,则可以使用GL_POINTS.您仍然必须创建顶点和片段着色器等,这是很多额外的工作.

If you really want to draw individual pixels one by one with OpenGL, you could use GL_POINTS. You'll still have to create vertex and fragment shaders, etc., which is a lot of extra work.

这篇关于使用OpenGl核心中的单个像素画一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆