问题描述
我正在尝试绘制一些已存储为顶点数组的轮廓:
I am trying to draw some contours that I have stored as vertex arrays:
typedef struct
{
float* vertices;
int nrPoints;
}VertexCurve;
list<VertexCurve> CurveList;
我正在使用opengl es 2.0书中的一些示例: http://opengles-book.com/
I am using some samples from an opengl es 2.0 book : http://opengles-book.com/
绘图方法如下:
void Draw ( ESContext *esContext )
{
UserData *userData = (UserData*)esContext->userData;
// Set the viewport
glViewport ( 0, 0, esContext->width, esContext->height );
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT );
// Use the program object
glUseProgram ( userData->programObject );
//glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
//glEnable(GL_SAMPLE_COVERAGE);
//glSampleCoverage(0.5, GL_FALSE);
glEnableVertexAttribArray ( 0 );
//glLineWidth(1);
for (list<VertexCurve>::iterator it = CurveList.begin();
it != CurveList.end(); it++)
{
// Load the vertex data
glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, (*it).vertices );
glDrawArrays ( GL_LINE_LOOP, 0, (*it).nrPoints );
}
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
}
另外,绘图的结果是:
我需要的是在OpenGL ES 2中具有更平滑的线条(抗锯齿)和我阅读的内容,可以通过多重采样来完成.从代码中可以看到,我尝试使用特定于此技术的一些方法,但是我无法完全理解它们的用法,并得到了不好的结果:
What i need is to have smoother lines (anti-aliased) and from what I read, in OpenGL ES 2 that can be done with multisampling. You can see from the code that I have tried using some methods specific to this technique but I was unable to fully understand their usage and got bad results:
如果有人可以向我解释如何获得抗锯齿的线条并使轮廓更平滑,我将不胜感激.
If someone can explain to me how to get anti-aliased lines and make the contours smoother, I will be very grateful.
推荐答案
可以使用令牌GL_MULTISAMPLE启用或禁用多重采样,默认情况下已启用.
Multisampling can be enabled or disabled using the token GL_MULTISAMPLE, and by default it is enabled.
为了确定当前活动的EGL曲面是否支持多重采样,请查询GL_SAMPLE_ BUFFERS的值:此处1表示支持,0表示不支持.然后GL_SAMPLES告诉每个像素存储了多少个样本.
In order to find out whether multisampling is supported by the currently active EGL surface, query the value of GL_SAMPLE_ BUFFERS: here 1 means supported, 0 indicates not supported. GL_SAMPLES then tells how many samples per pixel are stored.
所以我要做的就是在上下文属性列表中添加这两个属性:
So all I had to do was add those 2 attributes in the context attribute list :
EGLint attribList[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
EGL_DEPTH_SIZE, (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE,
EGL_STENCIL_SIZE, (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
EGL_SAMPLES, 4,
EGL_NONE
};
我将EGL_SAMPLE_BUFFERS设置为1以具有多重采样缓冲区,将EGL_SAMPLES设置为4,这样每个像素具有4个采样(FSAA x4).
I set EGL_SAMPLE_BUFFERS to 1 to have a multisample buffer and EGL_SAMPLES to 4 , in so having 4 samples per pixel (FSAA x4).
这篇关于如何在OpenGL ES 2.0中绘制反锯齿线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!