Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 点精灵Alpha混合问题_C++_Opengl_Glsl_Opengl 3_Glm Math - Fatal编程技术网

C++ 点精灵Alpha混合问题

C++ 点精灵Alpha混合问题,c++,opengl,glsl,opengl-3,glm-math,C++,Opengl,Glsl,Opengl 3,Glm Math,我正在尝试使用点精灵渲染3D空间中的大量星星。就alpha通道而言,我的纹理图像绝对是“好的”。它作为四边形渲染得非常好,但是当我渲染很多点精灵时,我可以看到图像的方形边框覆盖了一些图像。 上图显示了在我的立方体顶部很好地渲染的星星。在右下角,我希望看到一系列连续的恒星图像,它们是以“花”的模式绘制的 我做错了什么 片段着色器: #version 140 #extension GL_ARB_explicit_attrib_location : enable precision medium

我正在尝试使用点精灵渲染3D空间中的大量星星。就alpha通道而言,我的纹理图像绝对是“好的”。它作为四边形渲染得非常好,但是当我渲染很多点精灵时,我可以看到图像的方形边框覆盖了一些图像。

上图显示了在我的立方体顶部很好地渲染的星星。在右下角,我希望看到一系列连续的恒星图像,它们是以“花”的模式绘制的

我做错了什么

片段着色器:

#version 140

#extension GL_ARB_explicit_attrib_location : enable

precision mediump float;

uniform sampler2D uTexture;

void main( void )
{    
  gl_FragColor = texture2D( uTexture, gl_PointCoord );
}
顶点着色器:

#version 140

#extension GL_ARB_explicit_attrib_location : enable

precision mediump float;

layout (location = 0) in float aTheta; 

uniform float uK;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main( void )
{
  float x = cos( uK * aTheta ) * sin( aTheta );
  float y = cos( uK * aTheta ) * cos( aTheta );

  gl_Position  = projection * view * model * vec4( x, y, 0.0, 1.0 );
  gl_PointSize = 64.0;
}
代码:


也许深度筛选在捉弄你?在渲染精灵时尝试
glDepthMask(false)

尝试添加glDisable(GL\u DEPTH\u TEST)。谢谢,我接受了你的答案。成功了。我尝试启用GL_深度_测试,但没有尝试禁用它。glDepthMask(false)和glDisable(GL_DEPTH_TEST)都提供了所需的结果。@SparkyNZ很棒!我建议使用DepthMask,因为精灵可以通过正确的遮挡放置在左上角(立方体)体积后面。如果同时禁用深度测试,则卷后面的任何精灵都将在其顶部渲染。这一点很好。现在我还有别的事情要解决。我已经用点精灵创建了一个星域,现在它们都出现在立方体的顶部。
void CPoint::Render( void )
{
  g_PointProgram.UseProgram();

  glEnable( GL_PROGRAM_POINT_SIZE );
  glEnable( GL_POINT_SPRITE );

  // Set the alpha blending function
  glEnable( GL_BLEND );
  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
  glBlendEquation( GL_FUNC_ADD );

  glBindBuffer( GL_ARRAY_BUFFER, m_VBO );

  glm::mat4 Model = glm::mat4( 1.0 );

  Model = glm::translate( Model, glm::vec3( 2.0f, 0.0f, 4.0f ) );

  glm::mat4 Projection = g_Camera.GetProjection();
  glm::mat4 View       = g_Camera.GetView();

  g_PointProgram.SetUint( "uTexture", g_ImgStar.m_Texture );

  g_PointProgram.SetMatrix4fv( "model", Model );
  g_PointProgram.SetMatrix4fv( "view", View );
  g_PointProgram.SetMatrix4fv( "projection", Projection );

  g_PointProgram.SetFloat( "uK", m_Emitter.k );

  glActiveTexture( GL_TEXTURE0 );
  glBindTexture( GL_TEXTURE_2D, g_ImgStar.m_Texture );
  glEnable( GL_TEXTURE_2D );

  // Attributes
  glVertexAttribPointer( 0,                // 1st attribute array (only have 1)
                         1,                                        // One theta angle per particle
                         GL_FLOAT,                                 // Data is floating point type
                         GL_FALSE,                                 // No fixed point scaling
                         sizeof( Particle ),                       // No gaps in data
                         (void*) 0 );      // Start from "theta" offset within bound buffer


  glEnableVertexAttribArray( 0 );

  glDrawArrays( GL_POINTS, 0, NUM_PARTICLES );

  glDisableVertexAttribArray( 0 );
  glBindBuffer( GL_ARRAY_BUFFER, 0 );

  glDisable( GL_TEXTURE_2D );
}