OpenGL 4.1 Drawing a texture

I realize the code is in C++, but the OpenGL is the part I’m questioning.
I’ve been trying to render a Texture to the screen… this is my third attempt… first time was in Intermediate mode, second with method removed in OpenGL 3.
I now have a shader (inside the initialize function) and the code to draw at the bottom. Currently nothing renders, I used to get a untextured quad until I fixed an error in the glUniform1i

http://www.pastebucket.com/19567
This is the whole function.
Drawing starts at line 70
Can someone please help me, I mainly just need to see how it all fits together,
even a copy and paste from a working draw texture function or something that does the same would be sufficient from me to reverse engineer.

Lots of things to note here… I will be brutally honest. :stuck_out_tongue:

[]Don’t copy-paste. Instead, read up on theory; learn about things like matrix math, how GLSL and the shader pipeline works, and what VBOs really are. If you aren’t ready do actually do the reading, then you are barking up the wrong tree trying to write your own OpenGL code.
[
]It looks like you are creating and deleting your shaders and VBOs in the same function that you are drawing your textures. This is horrible practice. As a rule of thumb, try not to create or allocate things in your game loop rendering functions. Create things in the beginning of your application lifecycle; then render; then “clean up” your resources when the user is quitting.
[]gl_TexCoord, gl_MultiTexCood0, etc. are deprecated in modern pipeline. You need to define your own attributes and varyings.
[
]Don’t use ARB function calls in modern pipeline.
[]Don’t glEnable texturing – this is not necessary in modern pipeline.
[
]Pass zero to glUniform1i for samplers, not GL_TEXTURE0
[]You didn’t specify any texture coordinates – how will GL know what to sample from?
[
]Where is your perspective or orthographic projection matrix?

Honestly, your code looks like a copy-pasted mish-mash of different techniques that span both the programmable and fixed-function pipeline. It’s no surprise anything renders; pretty much every aspect of your code is not correct. Like I said; read some tutorials and stop copy-pasting, or use something other than raw OpenGL.

C/C++:
http://www.gamefromscratch.com/post/2013/02/27/Modern-OpenGL-resources-round-up.aspx

Java:

Is there a good modern opengl book you would recommend?
By modern I mean not as old. But I still wanna use OpenGL 2, not 3+ exclusively.

Butally honest, I like that

When I came into openGL 4.1 I brought along a lot of my old OpenGL 1.1 so the main reason I’m using things that are long long gone is that I don’t know what’s in and what’s out.
I do destroy the VBO per function call, but the shader is created once and never again.

I’ve taken note from the dot points and thank you :3
Not too sure how I’d provide the UV coordinates though

the reason the drawing part looks like Frankenstein is because I’ve been moving and trying all sorts of functions to try and get it to work by using the OpenGL specification which didn’t go so well.

I’ve come back with a new version of the function and this time there’s no errors and I understand what I’m doing. using Indexed draws. http://www.pastebucket.com/19672 I changed the shader and the drawing code, but nothing appears still on the screen.

Maybe to help this is the code that runs at the start of a frame and end

glClearColor(0.25f, 0.25f, 0.25f, 1);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glViewport(0, 0, windowSize.x, windowSize.y);

end:
glFlush();
SwapBuffers(hdc);

Here’s some OpenGL tutorials I’m currently going through. Really, start by going through such tutorials step by step and you’ll get there.

Where is your texcoord buffer? Why are you still using ARB extension calls? Don’t use “varying” for new versions of GLSL, instead you need “in” and “out” syntax.

So I’ve removed all ARB functions, added a texture coords and moved to the in and out keywords. aswell as have the shader just use the colour white to at least get a shape.
and I have results!

Still can’t see it?

zoom scan and enhance

There we go, one pixel :slight_smile: it’s progress
there’s still something going wrong and it might be the way I give it the vertices?
I’m also moving repeated code into functions for ease.
http://www.pastebucket.com/19690

You need an orthographic projection matrix. Vertex shader typically looks like this:

uniform mat4 projection;

in vec2 in_pos;

out vec4 out_pos; //gl_Position is deprecated

void main() {
    out_pos = projection * vec4(in_pos, 0.0, 1.0);
    ...
}

The matrix is fairly easy to compute, see here:
http://www.scratchapixel.com/lessons/3d-advanced-lessons/perspective-and-orthographic-projection-matrix/orthographic-projection/

Though typically in C++ you would use something like GLM which handles matrix math for you.
http://open.gl/transformations

You need to start reading a book and/or some tutorials. Copy-pasting will not get you very far.