Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:10:56+00:00 2026-05-26T23:10:56+00:00

I building a simple Framework for OpenGL UI’s for MonoTouch. I set up everything

  • 0

I building a simple Framework for OpenGL UI’s for MonoTouch. I set up everything and also succeeded rendering 3D Models, but a simple 2D texture object fails. The texture has a size of 256×256 so it’s not to large and its power of two.

Here is some rendering code( Note: I did remove the existing, and working code ):

// Render the gui objects ( flat )
Projection = Matrix4x4.Orthographic(0, WindowProperties.Width, WindowProperties.Height, 0);
View = new Matrix4x4();
GL.Disable(All.CullFace);
GL.Disable(All.DepthTest);
_Stage.RenderGui();

Stage:

public void RenderGui ()
{
    Draw(this);
    // Renders every child control, all of them call "DrawImage" when rendering something
}


public void DrawImage (Control caller, ITexture2D texture, PointF position, SizeF size)
{
    PointF gposition = caller.GlobalPosition; // Resulting position is 0,0 in my tests
    gposition.X += position.X;
    gposition.Y += position.Y;

    // Renders the ui model, this is done by using a existing ( and working vertex buffer )
    // The shader gets some parameters ( this works too in 3d space )   
    _UIModel.Render(new RenderParameters() {
        Model = Matrix4x4.Scale(size.Width, size.Height, 1) * Matrix4x4.Translation(gposition.X, gposition.Y, 0),
       TextureParameters = new TextureParameter[] {
           new TextureParameter("texture", texture)
       }
    });
}

The model is using a vector2 for positions, no other attributes are given to the shader.

The shader below should render the texture.

Vertex:

attribute vec2 position;        
uniform mat4 modelViewMatrix;           
varying mediump vec2 textureCoordinates;

void main()
{
    gl_Position = modelViewMatrix * vec4(position.xy, -3.0, 1.0);
    textureCoordinates = position;
}

Fragment:

varying mediump vec2 textureCoordinates;
uniform sampler2D texture;          

void main()
{
    gl_FragColor = texture2D(texture, textureCoordinates) + vec4(0.5, 0.5, 0.5, 0.5);
}

I found out that the drawing issue is caused by the shader. This line produces a GL_INVALID_OPERATION( It works with other shaders ):

GL.UniformMatrix4(uni.Location, 1, false, (parameters.Model * _Device.View * _Device.Projection).ToArray());

EDIT:

It turns out that the shader uniform locations changed( Yes i’m wondering about this too, because the initialization happens when the shader is completly initialized. I changed it, and now everything works.

As mentioned in the other thread the texture is wrong, but this is another issue ( OpenGL ES 2.0 / MonoTouch: Texture is colorized red )

The shader initialization with the GL.GetUniformLocation problem mentioned above:

[... Compile shaders ...]
// Attach vertex shader to program.
GL.AttachShader (_Program, vertexShader);

// Attach fragment shader to program.
GL.AttachShader (_Program, pixelShader);        

// Bind attribute locations
for (int i = 0; i < _VertexAttributeList.Length; i++) {
    ShaderAttribute attribute = _VertexAttributeList [i];
    GL.BindAttribLocation (_Program, i, attribute.Name);
}

// Link program
if (!LinkProgram (_Program)) {
    GL.DeleteShader (vertexShader);
    GL.DeleteShader (pixelShader);
    GL.DeleteProgram (_Program);

    throw new Exception ("Shader could not be linked");
}

// Get uniform locations
for (int i = 0; i < _UniformList.Length; i++) {
    ShaderUniform uniform = _UniformList [i];
    uniform.Location = GL.GetUniformLocation (_Program, uniform.Name);
    Console.WriteLine ("Uniform: {0} Location: {1}", uniform.Name, uniform.Location);
}

// Detach shaders
GL.DetachShader (_Program, vertexShader);
GL.DetachShader (_Program, pixelShader);

GL.DeleteShader (vertexShader);
GL.DeleteShader (pixelShader);

// Shader is initialized add it to the device
_Device.AddResource (this);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:10:57+00:00Added an answer on May 26, 2026 at 11:10 pm

    It turns out that the shader uniforms change at a unknown time. Everything is created and initialized when i ask OpenGL ES for the uniform location, so it must be a bug in OpenGL.

    Calling GL.GetUniformLocation(..) each time i set the shader uniforms solves the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing
Hi I am building a small simple JS framework for University. I am having
I am building simple blogging framework using PHP and MySQL, and on the add
I'm building a simple framework and hoping it will help me better understand OOP.
I'm building an application in the Zend Framework, but I'd like to implement a
I'm building a simple Todo List application where I want to be able to
I am building a simple Django app that will use scribd to display documents.
I'm building a simple ASP.NET web application in VS 2008 with a SQL 2005
I'm building a simple ice sliding puzzle to test uses of allegro. So far
I'm building a simple accounting app to be used for personal finance. A user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.