Skip to main content
gamedev.net
🔒 Locked

quad sizing

Started by jmg5 Jan 8, 2004 at 8:12 PM 4 replies 350+ views
Original Post
jmg5
jmg5
glBegin(GL_QUADS);                              
    glVertex3f(-1.0f, 1.0f, 0.0f);           
    glVertex3f( 1.0f, 1.0f, 0.0f);		
    glVertex3f( 1.0f,-1.0f, 0.0f);		
    glVertex3f(-1.0f,-1.0f, 0.0f);			
glEnd();
How would I change the size of this quad? For instance, how could I make it smaller? Longer? Wider? All help is appreciated.
Ostsol
Ostsol
Or you could use glScale. Of course, there''s not much point to that when you can just change the coorinates defined by glVertex. I do use glScale for changing the size of a generic quad (whose vertex data is in a VBO) that I use for my GUI system, though.
-Ostsol
jmg5
jmg5
Thanks.
Enokh
Enokh


glPushMatrix();
glTranslatef(Pos.x, Pos.y, 0);
glBegin(GL_QUADS);
// Quad x/y coords are it''s top left corner

glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(QuadWidth, 0.0f, 0.0f);
glVertex3f(QuadWidth, -QuadHeight, 0.0f);
glVertex3f(0.0f, -QuadHeight, 0.0f);

// Or it''s center

glVertex3f(-Width * 0.5f, Height * 0.5f, 0.0f);
glVertex3f( Width * 0.5f, Height * 0.5f, 0.0f);
glVertex3f( Width * 0.5f, -Height * 0.5f, 0.0f);
glVertex3f(-Width * 0.5f, -Height * 0.5f, 0.0f);

// Optimized to

Width *= 0.5f;
Height *= 0.5f;

glVertex2f(-Width, Height, 0.0f);
glVertex2f( Width, Height, 0.0f);
glVertex2f( Width, -Height, 0.0f);
glVertex2f(-Width, -Height, 0.0f);
glEnd();
glPopMatrix();

EGD Eric
EGD Eric
This could also do the trick: Let's say you want to make the quad one half the normal size:

glPushMatrix();
glTranslatef(xPos, yPos);


glScalef(0.5, 0.5, 1); //scale it to one half the size.
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glPopMatrix();

Of course, you could use variables for the width/height factors in glScalef: glScalef(scale_x, scale_y, 1);

[edited by - EGD Eric on January 10, 2004 3:58:21 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.