PDA

View Full Version : Keeping quads size when using VBO and glScale



raziza
07-13-2011, 12:02 AM
I want to draw many quads with textures - And on the right of them few more small quad with textures. (for ex. Image and text on the side)

I've mapped my window as pixels 2D and made it work with VBO. works great.

the problem is that i want to zoom in into area of quads without scaling the size of them. When i use glScale its affecting the quads size also (which is logically). I need just to affect their position.

Is there a way to do that?

Thanks.

BionicBytes
07-13-2011, 12:43 AM
Can you not just multiply the position of the text quads by the scale factor to calculate their positions without using glScalef?

raziza
07-13-2011, 01:26 AM
I guess you mean to update the vertex array.

I could, but then i would have to update my 100,000 or more quads in the VBO which mean 4 vertexes each.. and its takes CPU time which will affect the drawing in the end.

Alfonse Reinheart
07-13-2011, 02:24 AM
I guess you mean to update the vertex array.

No, he means that you compute a positional offset, that represents the scaled location of the text, to your vertex shader and have it add that to each of the vertex positions. Your shader need not know that this offset came from a scaled coordinate system.

raziza
07-13-2011, 04:01 AM
First of all, thanks for the help so far.

but,
i didn't quite understand. Can you give me an example for what you meant ?

By the way, I don't use (or know) shader on my program.
(I know the concept but not too much, I will learn more about it now)

there is not a "none-shader way" to do that?

BionicBytes
07-13-2011, 06:55 AM
The non shader approach is to build and supply a model matrix to OpenGL. This is exactly what glScalef does. However using the fixed function pipe line is limited and for what you need to do vertex shader code is required.

raziza
07-13-2011, 07:53 AM
Ok..

I will read allot more now about shaders and hopefully will understand it and your answers :)

Most thanks guys..

raziza
07-17-2011, 07:48 AM
Hi again,
Read allot about GLSL again.
And i guess i will have to ask for an hint or direction.

I narrowed my problem only to two quads, and my goal is to zoom in between them with out affecting their sizes, just their pos.

Each quad vertexes had been calculated before from its center point, so the quad will be in the center of the real position.

As i got it, i need to calculate the new gl_position(s) of all the new points. I removed the glscale from from the code and i sent the factor as uniform to the shader, but now what? each multiply is affecting all and i got the same result like glScale.

I'm hopeless here.

thanks.

raziza
07-18-2011, 09:29 AM
OK, found a solution! just to close this issue in case someone need an answer but me.

I filled my quads vertexes array with the centers of the quads.
Meaning that all 4 vertexes of each quad will be its center.

In addition, I'v add a vertex attribute to each which indicates the vertex position - TopLeft\TopRight\BottomRight\BottomLeft (-1,-1)(1,-1)(1,1)(-1,1)

To make it play together, I've build vertex shader which computes each vertex, using the attribute and the center of the quad (with additional scale params - just to see the quad bigger or smaller).

That's it.

this is what you meant? or there is an easier way ? (Now that i speak GLSL :D )

Thanks all for reply.
and the rest for ignoring :p