Git Product home page Git Product logo

Comments (6)

mosra avatar mosra commented on April 28, 2024

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?

from magnum.

miguelmartin75 avatar miguelmartin75 commented on April 28, 2024

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();

from magnum.

mosra avatar mosra commented on April 28, 2024
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).

from magnum.

mosra avatar mosra commented on April 28, 2024

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.

from magnum.

miguelmartin75 avatar miguelmartin75 commented on April 28, 2024

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.

from magnum.

mosra avatar mosra commented on April 28, 2024

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.

from magnum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.