Jump to content
  • Advertisement
DevAndroid

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

Recommended Posts

How to set those renderstate ?

Expected result is that png in attach files.

A square round courners (color bright blue).

square.png

Share this post


Link to post
Share on other sites
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.

 

 

Share this post


Link to post
Share on other sites
Posted (edited)
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);

 

Edited by DevAndroid

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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"

 

Share this post


Link to post
Share on other sites
Posted (edited)

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

Edited by DevAndroid

Share this post


Link to post
Share on other sites
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 ;) !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!