Opengl 3.3 load & display texture
#2 Members - Reputation: 785
Posted 14 January 2011 - 07:53 AM
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
#3 Members - Reputation: 127
Posted 14 January 2011 - 08:59 AM
Loading textures has not changed in GL3
http://www.opengl.org/wiki/Tutorials
Hmm I don't find the glTexEnv function in GL3
#7 Members - Reputation: 840
Posted 14 January 2011 - 03:44 PM
another thing I've noticed is glEnable(GL_TEXTURE_2D),
GL_TEXTURE_2D is no longer a valid enum
another thing I've noticed is glEnable(GL_TEXTURE_2D),
GL_TEXTURE_2D is no longer a valid enum
As no longer fixed function pipeline, the GL_TEXTURE_2D (and the others) flag is pointless.
glDisable(GL_TEXTURE_2D) = dont send to the shader.
Just to clarify this quote, glEnable/glDisable(GL_TEXTURE_2D) has no effect on shader pipeline. When you have a sampler at location 0, it will always sample the texture bound to glActiveTexture(GL_TEXTURE0), regardless of the enabled state of GL_TEXTURE_2D.
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game
#8 Members - Reputation: 127
Posted 14 January 2011 - 05:05 PM
Initialization functions
Loading Vbo & Texture
Drawing and shader source
#9 Members - Reputation: 840
Posted 14 January 2011 - 05:28 PM
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game
#10 Members - Reputation: 127
Posted 14 January 2011 - 05:33 PM
http://codepad.org/N6G4L0mO
Loading vbo & texture
http://codepad.org/txCRarG5
Drawing + shader source
http://codepad.org/78ylAPSm
#11 Members - Reputation: 840
Posted 14 January 2011 - 05:38 PM
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game
#13 Members - Reputation: 840
Posted 14 January 2011 - 05:57 PM
I think code posting works fine with '[' code ']' tags
Couple things I notice:
1) Always, always call glGetError at least once during your draw loop. It will help you find problems.
2) Nowhere have you bound your "sampler2D tex" to texture channel 0. You have to do this with glUniform1i like any other uniform int. I believe it to be undefined otherwise, and you may be sampling the wrong texture channel. This doesn't explain why you don't at least see any polygons though.
3) I have no idea what your modelview matrix is. It's set during initialization but I don't know from what.
Also I'll recommend changing your clearcolor to something other than white. Sometimes illegal texture sampling can cause a white triangle, and this will confuse you because you won't see a polygon at all. Choose some nonblack - nonwhite random color for the clearColor.
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game
#15 Members - Reputation: 840
Posted 14 January 2011 - 06:38 PM
1) Can you draw your quad with no shaders, no vbos, using just your matrices and the fixed function pipeline?
2) Can you get it to work with only vertex arrays?
3) With fixed function and VAO's?
4) If you get all that, a simple shader that only outputs a single color?
5) Then try adding texturing?
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game
#16 Members - Reputation: 840
Posted 14 January 2011 - 06:49 PM
Actually this seems like it might be ok.
If there is a mismatch between the incoming dimensionality and the attribute's dimensionality, OpenGL will satisfy it. If the vertex data has more components than the shader attribute uses, the extra components are ignored. If the vertex data specifies fewer than the shader attribute uses, then the unfilled-in components are 0, except for the 4th component which is set to 1.
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game
#17 Members - Reputation: 127
Posted 16 January 2011 - 03:35 PM
Hmm thats unfortunate. I don't see what else exactly is the problem, so you may want to try regressing a bit here to fixed function and debug pieces of it at a time. I know it's a pain though, but it's probably the best way to figure out what part is giving you problems.
1) Can you draw your quad with no shaders, no vbos, using just your matrices and the fixed function pipeline?
2) Can you get it to work with only vertex arrays?
3) With fixed function and VAO's?
4) If you get all that, a simple shader that only outputs a single color?
5) Then try adding texturing?
It must be something with the shaders and/or my matrices. I can draw from the VAO or immediate mode if I intentionally don't compile the shaders. Perhaps things are being rendered outside of the view.
My BuildOrthoProjMatrix function is based on the glOrtho function as I see it here glOrtho [size=1]
void BuildOrthoProjMat(float* amat, float al, float ar, float ab, float at, float azn, float azf){[/size]
*((glm::mat4*)amat) = glm::mat4();
float tx = (ar+al)/(ar-al);
float ty = (at+ab)/(at-ab);
float tz = (azf+azn)/(azf-azn);
amat[0] = 2/(ar-al);
amat[5] = 2/(at-ab);
amat[10] = -2/(azf-azn);
amat[12] = tx;
amat[13] = ty;
amat[14] = tz;
}When I call this function with these arguments BuildOrthoProjMat((float*)&mProjectionMatrix, 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1, 1);Does this look like the proper transformed vector?
vec4 worldVec(800, 600, 0, 1);
vec4 screenVec = mProjectionMatrix * worldVec;
gives me a screenVec of (3, 3, 0, 1);
Is it supposed to give me normalized device coordinates? In that case it seems like it is outside of the view.
#18 Members - Reputation: 840
Posted 16 January 2011 - 09:31 PM
I did a quick test:
glm::mat4 m = glm::gtx::matrix_projection::ortho<float>(0,800.f,0,800.f,-1.f,1.f);
glm::vec4 v(800,800,0,1);
glm::vec4 vt = m*v;
and vt comes out to be (0.9999,0.9999, 0, 1), which seems like right on the edge of the NDC like I would expect.
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game
#19 Members - Reputation: 127
Posted 16 January 2011 - 11:20 PM
When I use this matrix instead I get the expected vector, so it must have been a problem with my matrix creation. (Is there a reason why you used the gtx instead of the gtc ortho function?)
Edit: Okay that seems to have been the problem. Thanks for the great help, karwosts.
#20 Members - Reputation: 840
Posted 17 January 2011 - 12:10 AM
This is just speculation, but:
You have a mat4* pointer amat, which you then access by
amat[5] = blah;
Wouldn't this give you a reference to the 6th mat4 in an array of mat4s?
The proper way that I know of to access the fifth element of a mat4 would be:
(*amat)[1][1] = blah;
Maybe your way works too, but I wouldn't think it would, unless that's overloaded somehow.
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game






