Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Sat Oct 25, 2014 3:14 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Mon May 20, 2013 12:15 am 
Level 1 Cleric

Joined: Tue May 14, 2013 10:56 am
Posts: 10
I need to rotate a texture in OpenGL 4.3

What's the best way to do this using shaders? Should i use a rotation matrix or change the way the file is read in?


Top
 Profile  
 
PostPosted: Mon May 20, 2013 12:27 am 
Digerati

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1816
Location: burrowed
It depends on what you try to achieve.

If you want to rotate the texture in the fragment shader you could probably achieve it by applying sin() and cos() functions to the uv coordinates. That however can result in the edges of the texture poking outside the actual polygon, so you're probably better off applying a rotation matrix to the whole mesh.

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
PostPosted: Mon May 20, 2013 1:08 am 
Level 1 Cleric

Joined: Tue May 14, 2013 10:56 am
Posts: 10
weezl wrote:
It depends on what you try to achieve.

If you want to rotate the texture in the fragment shader you could probably achieve it by applying sin() and cos() functions to the uv coordinates. That however can result in the edges of the texture poking outside the actual polygon, so you're probably better off applying a rotation matrix to the whole mesh.


Thanks, I'll try rotating the whole mesh.


Top
 Profile  
 
PostPosted: Wed May 22, 2013 9:08 am 
Level 1 Cleric

Joined: Tue May 14, 2013 10:56 am
Posts: 10
Ok, I've got a rotation matrix (0,-1; 1, 0).
Now with previous versions of OpenGL using the fixed pipeline, I would use glTranslate, etc. To move to the origin then rotate.

How do I do translate with OpenGL 4? What does the matrix look like?
Also do I apply my orthogonal perspective matrix before or after transforming and are there any good text tutorials for opengl 4/3?

My shader source can be found: https://gist.github.com/selekton99/333dd820b41de429eeec


Top
 Profile  
 
PostPosted: Wed May 22, 2013 1:36 pm 
Digerati

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1816
Location: burrowed
To translate using a matrix, you need a mat4 like this

Code:
mat4 translate = mat4(
1,0,0,0,
0,1,0,0,
0,0,1,0,
x,y,z,1);


For orthographic perspective you basically dont *need* a matrix, the original space the shader works in is screespace in normalized units (-1|-1 bottom left, 1|1 top right); You can easily transform it to screen coordinates if you know the screensize, if that's what you want.

But if you want to use an orthogonal matrix you need to modify your position like the following:
Code:
gl_Position = Orthogonalmatrix * vec4(InVector,0,1);

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
PostPosted: Wed May 22, 2013 9:19 pm 
Level 1 Cleric

Joined: Tue May 14, 2013 10:56 am
Posts: 10
Ok, I'll describe my problem a bit better.
I'm trying to draw text by using a Bitmap. I've generated it into a texture. Using a 2D orthogonal matrix I can convert screen co-ords to the -1,etc
My problem is the texture is drawing rotated 90 degrees. To solve this I think I need to translate to origin, rotate 90, translate back to original position.
How do I rotate the 2 triangles?


Top
 Profile  
 
PostPosted: Sun May 26, 2013 5:52 am 
Level 1 Cleric

Joined: Tue May 14, 2013 10:56 am
Posts: 10
Fixed by changing texture coordinates for anybody else who stumbles across this


Top
 Profile  
 
PostPosted: Wed May 29, 2013 7:50 am 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 7114
Location: Wilts, Englandshire
Glad you sorted it, thanks for posting the solution. It seems obvious now. 20/20 hindsight.

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
PostPosted: Wed Jun 12, 2013 3:21 pm 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3952
Location: Ferriday, LA, US
The texture coordinate orientation does confuse. It is best to remember that the orientation of the Y axis when dealing with OpenGL is always inverted. Once I figured out that starting to define coordinates from the bottom corner, and not the top corner, works best... no more texture rotation problems.

_________________
Wear your sorrows with a smile!


Top
 Profile  
 
PostPosted: Tue Jun 18, 2013 10:23 am 
Level 1 Cleric

Joined: Tue May 14, 2013 10:56 am
Posts: 10
Mugai wrote:
The texture coordinate orientation does confuse. It is best to remember that the orientation of the Y axis when dealing with OpenGL is always inverted. Once I figured out that starting to define coordinates from the bottom corner, and not the top corner, works best... no more texture rotation problems.


I'll keep that in mind, Thanks.

Codehead wrote:
Glad you sorted it, thanks for posting the solution. It seems obvious now. 20/20 hindsight.


I should be thanking you, I used your Bitmap Font File Generator.


Top
 Profile  
 
PostPosted: Wed Jun 19, 2013 7:03 pm 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 7114
Location: Wilts, Englandshire
selekton99 wrote:
I should be thanking you, I used your Bitmap Font File Generator.


Lol, you're welcome. 8) I can't believe how much that tool still gets around.

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group