Render Texture from PNG to Screen not working correctly OpenGL ES 3.0

Started by
28 comments, last by DevAndroid 5 years, 11 months ago

How to set those renderstate ?

Expected result is that png in attach files.

A square round courners (color bright blue).

square.png

Advertisement

Ok, i think you have Z-fighting problem.

1) You can set different Z coordinates for texture/font(additional uniform variable for vertex shader,  0.5 - for text, 0.0 - for texture) or use glPolygonOffset function.

2) also you can use glBlendFunc with Z-Write Disable.

 

 

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

31 minutes ago, Andrey OGL_D3D said:

You can set different Z coordinates for texture/font(additional uniform variable for vertex shader,  0.5 - for text, 0.0 - for texture) or use glPolygonOffset function.

I'm not sure to correctly understand this method. Should I add a glPolygonOffset(0,0) before the draw ?

 

31 minutes ago, Andrey OGL_D3D said:

also you can use glBlendFunc with Z-Write Disable.

I have those two lines that make work the font rendering.


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Should I add an other glBlendFunc ? Which one exactly ?

Maybe it could be the ALPHA problem ?

Please, I need some clarifications about those steps on my code, thank you!

 

EDIT:

I added those two lines on the init() but nothing changed :


glDisable(GL_DEPTH_TEST);
glDepthFunc(GL_NEVER);

 

6 hours ago, DevAndroid said:

I'm not sure to correctly understand this method


const char           gVertexShader[] =
        "#version 320 es\n"
                "layout (location = 0) in vec4 vertex;\n"
                "out vec2 TexCoords;\n"
        "uniform mat4 projection;\n"
		"uniform float z;\n"
                "void main() {\n"
                "  gl_Position = projection * vec4(vertex.xy, z, 1.0);\n"
        "  TexCoords = vertex.xy;\n"
                "}\n"

Cluster::printTexture
{
	glUniform1f(uniformHandleZ, 0.0f);
}

Cluster::printText
{
	glUniform1f(uniformHandleZ, 0.5f);
}

// Order Rendering
printTexture(...)
printText(...)

Also you should consider order rendering of texture/text

 

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

Hello Andrey,

I tried this code and it seems that I have no display at all now...

16 hours ago, Andrey OGL_D3D said:

" gl_Position = projection * vec4(vertex.xy, z, 1.0);\n"

Someone told me about this line :

 "This line is setting the texture coordinates to be the same as the vertex coordinates. So if you're drawing a quad at (96,96) to (128, 128), then your texture coordinates will be (96, 96) to (128, 128). But since you're using the GL_TEXTURE_2D target, the texture coordinates should be normalized. Otherwise, you'll be seeing just the edge color of the texture repeated across the quad. That probably not what you want. You probably do want to use 0-1 as the texture coords in both x and y directions."

What do you think? Should I just modify the way I put my vertices and it will resolve the problem ?

Ok, Again it is my mistake:


"#version 320 es\n"
                "layout (location = 0) in vec4 vertex;\n"
                "out vec2 TexCoords;\n"
        "uniform mat4 projection;\n"
		"uniform float z;\n"
                "void main() {\n"
                "  gl_Position = projection * vec4(vertex.xy, z, 1.0);\n"
        "  TexCoords = vertex.zw;\n"
                "}\n"

 

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

Still nothing... I'm not even able to get back this result ...

On 5/23/2018 at 1:15 PM, DevAndroid said:

In attach you'll see what's the result. I expect a full blue square in the middle like the png is but it's not. (But position is correct, that's a good point)

IMG_20180516_171103__01.jpg

Here you'll find the details of what I'm doing.

https://gist.github.com/AhmedX6/c18a753ea1d0ab09c03238c4d6395c3a

 

Thank you so much for your patience... I'm not that good in OpenGL. I'm still learning :S


printText()
{
...
	glUniform1f(this->mZShaderHandle, 0.0f);
...
}
printTexture(
{
...
	glUniform1f(this->mZShaderHandle, 0.5f);
...
}

printAll()
{
	printText...
	printTexture...
}

It's time to try to create simple project for Windows :)) and attach it to github ;) !

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

Yes ok I'll try, I'll keep you in touch if I find a solution :) Thank you !!

This topic is closed to new replies.

Advertisement