Blending of zlayers functionality copied to NOMADVRLib

parent f6f85797
......@@ -102,7 +102,7 @@ const char *const IsoTransparentShaders [] = {"Iso Transparent Renderer",
nullptr
};
const char *const IsoBlendShaders [] = {
const char *const IsoBlendShaders [] = {"Iso Transparent Blend",
// vertex shader
#if defined(WIN32) || defined(CAVE)
"#version 410 core\n"
......@@ -110,13 +110,13 @@ const char *const IsoBlendShaders [] = {
"#version 300 es\n"
#endif
"uniform mat4 matrix;\n"
"layout(location = 0) in vec4 position;\n"
"layout(location = 0) in vec3 position;\n"
"layout(location = 1) in vec2 v2TexCoordsIn;\n"
"out vec2 v2TexCoord;\n"
"void main()\n"
"{\n"
" v2TexCoord = v2TexCoordsIn;\n"
" gl_Position = matrix * vec4(position.xyz, 1);\n"
" gl_Position = matrix * vec4(position, 1);\n"
"}\n",
//fragment shader
"#version 410 core\n"
......
......@@ -346,4 +346,63 @@ glDepthMask(GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return glGetError();
}
GLenum SetupBlending (GLuint *vao, GLuint *vertex, GLuint *indices)
{
float z = 0.0f; //(m_fNearClip + m_fFarClip) / 2.0f;
const float points[] = {
-1, -1, z, 0, 0,
-1, 1, z, 0, 1,
1, 1, z, 1, 1,
1, -1, z, 1, 0 };
glGenVertexArrays(1, myvao);
glBindVertexArray(*myvao);
glGenBuffers(1, vertex);
glBindBuffer(GL_ARRAY_BUFFER, *vertex);
glBufferData(GL_ARRAY_BUFFER, 4 * 5 * sizeof(GLfloat), points, GL_STATIC_DRAW);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error after glBufferData: %d, %s, l %d\n", e, gluErrorString(e), __LINE__);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error: %d, %s, l %d\n", e, gluErrorString(e), __LINE__);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error: %d, %s, l %d\n", e, gluErrorString(e), __LINE__);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error: %d, %s, l %d\n", e, gluErrorString(e), __LINE__);
glGenBuffers(1, index);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error: %d, %s, l %d\n", e, gluErrorString(e), __LINE__);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *index);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error: %d, %s, l %d\n", e, gluErrorString(e), __LINE__);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(iData), iData, GL_STATIC_DRAW);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error: %d, %s, l %d\n", e, gluErrorString(e), __LINE__);
return e;
}
void DeleteBlendingBuffers(GLuint *vao, GLuint *vertex, GLuint *indices)
{
glDeleteBuffers(1, vertex);
glDeleteBuffers(1, indices);
glDeleteVertexArrays(1, vao);
}
void BlendTextures(GLuint textures)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for (int zl = ZLAYERS - 1; zl >= 0; zl--) {
glBindTexture(GL_TEXTURE_2D, textures[2 + zl]);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment