我正在使用glLineStipple()在OpenGL 2.0的行上创建模式。没关系,但模式并不恒定,他们总是在挥手。
有没有办法用旧的OpenGL函数或着色器解决这个问题?
我正在使用vtk的mapper及其顶点和片段着色器
/*=========================================================================
Program: Visualization Toolkit
Module: vtkglPolyDataVSNoLighting.glsl
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexMC;
// material property values
//VTK::Color::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
// Texture coordinates
//VTK::TCoord::Dec
void main()
{
//VTK::Color::Impl
//VTK::TCoord::Impl
gl_Position = VCDCMatrix * MCVCMatrix * vertexMC;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkglPolyDataFSNoLighting.glsl
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
varying vec4 fcolor;
// Texture coordinates
//VTK::TCoord::Dec
// material property values
uniform float opacityUniform; // the fragment opacity
uniform vec3 ambientColorUniform; // intensity weighted color
uniform vec3 diffuseColorUniform; // intensity weighted color
//VTK::Color::Dec
// picking support
//VTK::Picking::Dec
// Depth Peeling Support
//VTK::DepthPeeling::Dec
void main()
{
vec3 ambientColor = ambientColorUniform;
vec3 diffuseColor = diffuseColorUniform;
float opacity = opacityUniform;
// Note that the above will always define vec3 ambientColor, vec3 diffuseColor and float opacity
gl_FragColor = vec4(ambientColor + diffuseColor, opacity);
//VTK::TCoord::Impl
if (gl_FragColor.a <= 0.0)
{
discard;
}
//VTK::DepthPeeling::Impl
//VTK::Picking::Impl
}
它就是那样的
................
glLineStipple(2, 0x00FF);
glEnable(GL_LINE_STIPPLE);
glMultiDrawElements(GL_LINE_STRIP,
(GLsizei *)(&this->Lines.elementsArray[0]),
GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid **>(&(this->Lines.offsetArray[0])),
(GLsizei)this->Lines.offsetArray.size());
glDisable(GL_LINE_STIPPLE);
................
答案 0 :(得分:2)
经典线条点画在光栅化过程中通过将点画图案视为位掩码并使用栅格坐标进行按位AND运算来完成。这就是为什么当你在屏幕上移动窗口,摄像机视点等时它会闪烁。
现代硬件的更好方法是使用1-D纹理作为alpha蒙版实现点画,GL_TEXTURE_WRAP_S设置为GL_REPEAT,并根据该段的长度设置线上每个点的纹理坐标。您可能仍会在mipmap边界处获得潜在的不连续性,但它不应该差不多。在顶点和片段着色器之间执行的透视正确插值应该比经典点画更好。