Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Texturing Problem using OpenTK/OpenGL 3.3


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 addiem7c5   Members   -  Reputation: 103

Like
0Likes
Like

Posted 26 February 2013 - 03:54 PM

I am having troubles getting texturing working in my OpenTK/OpenGL 3.3 code. I am sure it is something simple that I am missing, but I just can't seem to get a texture on the square I am rendering. (I'm writing a rendering framework for a game).

The relevant code pieces are:

//setup Texcoord array.
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject[2]);
GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * texcoord_information.Count), texcoord_information.ToArray(), BufferUsageHint.StaticDraw);
GL.EnableVertexAttribArray(2);
GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 0, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
//Set up our textures
for(int i = 0; i < Textures.Count; i++)
{
    Console.WriteLine("Preparing texture.");
    Uniform_To_Texture[GL.GetUniformLocation(Shader.GetProgram(), "diffuse")] = Textures[i];
}
//Render

int texture_unit = 0;
foreach (KeyValuePair<int, ITexture> kvp in Uniform_To_Texture)
{
    GL.Uniform1(kvp.Key, texture_unit);
    GL.ActiveTexture(TextureUnit.Texture0 + texture_unit);
    GL.BindTexture(TextureTarget.Texture2D, kvp.Value.GetTextureHandle());
    texture_unit++;
}
if (!GL.IsVertexArray(VertexArrayObject))
    throw new OpenGLException("Vertex Array Object not set up correctly, cannot render!");
GL.BindVertexArray(VertexArrayObject);
GL.DrawArrays(BeginMode.Triangles, 0, Vertices.Count);
GL.BindVertexArray(0);

 

Then the vertex and fragment shaders are:

//Vertex shader
#version 330
uniform mat4 viewmatrix, projmatrix, transformmatrix;

in vec3 position;
in vec3 normal;
in vec2 texcoord;

varying vec2 texturecoord;

void main()
{
    texturecoord = texcoord;
    gl_Position = projmatrix * viewmatrix * transformmatrix * vec4(position, 1.0) ;
}

//Fragment Shader
#version 330
uniform sampler2D diffuse;
varying vec2 texturecoord;

out vec4 color;
void main(void)
{
    color = texture2D(diffuse, texturecoord);
}

 

The square I am rendering is just coming up white, if that helps any. 



Sponsor:

#2 addiem7c5   Members   -  Reputation: 103

Like
0Likes
Like

Posted 26 February 2013 - 07:55 PM

Visual Studio wasn't updating my .dll file, that is the cause of this problem. It is fixed now.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS