New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flat shader #31

Closed
miguelmartin75 opened this Issue Dec 10, 2013 · 6 comments

Comments

Projects
None yet
2 participants
@miguelmartin75
Contributor

miguelmartin75 commented Dec 10, 2013

When trying to create a flat shader, the following warning is outputted:

AbstractShaderProgram: linking succeeded with the following message:
WARNING: Could not find vertex shader attribute 'textureCoordinates' to match BindAttributeLocation request.

Here is what this warning looks like (visually within an actual program):

screen shot 2013-12-10 at 8 47 35 pm

As you can see, no texture(s) is rendered properly. Note, the screen is cleared white to see the black rendered 'textures' easier. The code for the above is located here (header/source), and the same result occurs for your textured triangle example (a black triangle is rendered).

Running Mac OS X 10.9.

Compiler:

Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

OpenGL context information:

Vender: Intel Inc.
Renderer: Intel HD Graphics 3000 OpenGL Engine
Version: 3.3 INTEL-8.18.27
@mosra

This comment has been minimized.

Show comment
Hide comment
@mosra

mosra Dec 10, 2013

Owner

The main cause should be fixed in ef83211 (why the heck the compiler issued only a warning?!), but the issue shouldn't happen on GL 3.3 in the first place, only on GL < 3.2 (as ARB_explicit_attrib_location isn't supported there). Also, I couldn't find any issue with textured-triangle example. Is the shader compiler printing similar warning?

Owner

mosra commented Dec 10, 2013

The main cause should be fixed in ef83211 (why the heck the compiler issued only a warning?!), but the issue shouldn't happen on GL 3.3 in the first place, only on GL < 3.2 (as ARB_explicit_attrib_location isn't supported there). Also, I couldn't find any issue with textured-triangle example. Is the shader compiler printing similar warning?

@miguelmartin75

This comment has been minimized.

Show comment
Hide comment
@miguelmartin75

miguelmartin75 Dec 11, 2013

Contributor

I'm not sure why, but I'm still getting black instead of the texture. At first I thought it was my image loading code, but it's not. As you can see below.
screen shot 2013-12-12 at 2 30 58 am

But I just keep getting a black triangle when trying to get it to work with magnum.

screen shot 2013-12-10 at 9 46 08 pm

The image I load uses stb_image, and it is in RGBA8 format.

Here's my image loading code:

auto imageData = util::loadImage("stone.jpg");
Magnum::ImageReference2D image{Magnum::ColorFormat::RGBAInteger, 
Magnum::ColorType::UnsignedByte,
 {imageData.width, imageData.height}, 
imageData.pixels.get()};

texture.setWrapping(Magnum::Sampler::Wrapping::ClampToEdge)
.setMagnificationFilter(Magnum::Sampler::Filter::Linear)
.setMinificationFilter(Magnum::Sampler::Filter::Linear)
.setImage(0, Magnum::TextureFormat::RGBA8, image);

Here's my code to set up the buffers/mesh object(s):

struct vertex
{
   Vector2 position;
   //Color4 colour;
   Vector2 textureCoords;
};
const int SIZE = 3;
constexpr static std::array<vertex, SIZE> vertices{{
        { {-300, -300}, /*{},*/ {0, 0} },
        { {300, -300}, /*{},*/  {1, 0} },
        { {0, 300}, /*{},*/ {0.5f, 1} },
}};

buffer.setData(vertices, Magnum::Buffer::Usage::StaticDraw);

mesh.setPrimitive(Mesh::Primitive::TriangleStrip).setVertexCount(SIZE)
.addVertexBuffer(buffer, 0, Shader::Position(), Shader::TextureCoordinates());

Here's my rendering code:

shader.setTransformationProjectionMatrix(Magnum::Matrix3::projection({640, 480}));
texture.bind(Magnum::Shaders::Flat2D::TextureLayer);

shader.use(); // this is a Flat2D shader

mesh.draw();
Contributor

miguelmartin75 commented Dec 11, 2013

I'm not sure why, but I'm still getting black instead of the texture. At first I thought it was my image loading code, but it's not. As you can see below.
screen shot 2013-12-12 at 2 30 58 am

But I just keep getting a black triangle when trying to get it to work with magnum.

screen shot 2013-12-10 at 9 46 08 pm

The image I load uses stb_image, and it is in RGBA8 format.

Here's my image loading code:

auto imageData = util::loadImage("stone.jpg");
Magnum::ImageReference2D image{Magnum::ColorFormat::RGBAInteger, 
Magnum::ColorType::UnsignedByte,
 {imageData.width, imageData.height}, 
imageData.pixels.get()};

texture.setWrapping(Magnum::Sampler::Wrapping::ClampToEdge)
.setMagnificationFilter(Magnum::Sampler::Filter::Linear)
.setMinificationFilter(Magnum::Sampler::Filter::Linear)
.setImage(0, Magnum::TextureFormat::RGBA8, image);

Here's my code to set up the buffers/mesh object(s):

struct vertex
{
   Vector2 position;
   //Color4 colour;
   Vector2 textureCoords;
};
const int SIZE = 3;
constexpr static std::array<vertex, SIZE> vertices{{
        { {-300, -300}, /*{},*/ {0, 0} },
        { {300, -300}, /*{},*/  {1, 0} },
        { {0, 300}, /*{},*/ {0.5f, 1} },
}};

buffer.setData(vertices, Magnum::Buffer::Usage::StaticDraw);

mesh.setPrimitive(Mesh::Primitive::TriangleStrip).setVertexCount(SIZE)
.addVertexBuffer(buffer, 0, Shader::Position(), Shader::TextureCoordinates());

Here's my rendering code:

shader.setTransformationProjectionMatrix(Magnum::Matrix3::projection({640, 480}));
texture.bind(Magnum::Shaders::Flat2D::TextureLayer);

shader.use(); // this is a Flat2D shader

mesh.draw();
@mosra

This comment has been minimized.

Show comment
Hide comment
@mosra

mosra Dec 11, 2013

Owner
Magnum::ColorFormat::RGBAInteger

I think one problem might be here. TextureFormat::RGBA8 should match ColorFormat::RGBA (or, in GL, the glTexImage2D() function requires GL_RGBA format for GL_RGBA8 internalFormat).

Owner

mosra commented Dec 11, 2013

Magnum::ColorFormat::RGBAInteger

I think one problem might be here. TextureFormat::RGBA8 should match ColorFormat::RGBA (or, in GL, the glTexImage2D() function requires GL_RGBA format for GL_RGBA8 internalFormat).

@mosra

This comment has been minimized.

Show comment
Hide comment
@mosra

mosra Dec 11, 2013

Owner

If that doesn't help, try to trace the application in ApiTrace, if possible, and check for GL errors there, or manually pinpoint the GL error with the following:

Debug() << Renderer::error();

This prints GL error name if any occured since last call to Renderer::error() (or since the application started). Sadly OSX doesn't support proper OpenGL debug output yet, so there is no better approach to find the error.

Owner

mosra commented Dec 11, 2013

If that doesn't help, try to trace the application in ApiTrace, if possible, and check for GL errors there, or manually pinpoint the GL error with the following:

Debug() << Renderer::error();

This prints GL error name if any occured since last call to Renderer::error() (or since the application started). Sadly OSX doesn't support proper OpenGL debug output yet, so there is no better approach to find the error.

@miguelmartin75

This comment has been minimized.

Show comment
Hide comment
@miguelmartin75

miguelmartin75 Dec 11, 2013

Contributor

When I printed out the error after I uploaded the texture data, I got a:

Renderer::Error::InvalidOperation

And now I fixed this issue, by doing as you suggested and using ColorFormat::RGBA. Thank you. :)

screen shot 2013-12-12 at 3 01 12 am

I think I was just a bit confused, as there are various options you must provide for the format of the image. And I thought RGBAInteger was appropriate for my scenario.

Contributor

miguelmartin75 commented Dec 11, 2013

When I printed out the error after I uploaded the texture data, I got a:

Renderer::Error::InvalidOperation

And now I fixed this issue, by doing as you suggested and using ColorFormat::RGBA. Thank you. :)

screen shot 2013-12-12 at 3 01 12 am

I think I was just a bit confused, as there are various options you must provide for the format of the image. And I thought RGBAInteger was appropriate for my scenario.

@mosra

This comment has been minimized.

Show comment
Hide comment
@mosra

mosra Dec 11, 2013

Owner

You're welcome, glad it's fixed :-) I should probably update the ColorFormat, ColorType and TextureFormat documentation and list values the user probably wants to use. The GL specification also isn't exactly helpful in this case, as information about the formats and allowed combinations is scattered around the whole document.

Owner

mosra commented Dec 11, 2013

You're welcome, glad it's fixed :-) I should probably update the ColorFormat, ColorType and TextureFormat documentation and list values the user probably wants to use. The GL specification also isn't exactly helpful in this case, as information about the formats and allowed combinations is scattered around the whole document.

mosra added a commit that referenced this issue Dec 12, 2013

@mosra mosra added this to the 2014.01 milestone Feb 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment