In this post I am going to show a simple way to learn how to do Scaling in OpenGL. Scaling is a property of transformation which helps increasing and decreasing the size of an object in computer graphics. The alteration in the size of object is done in each of the axis - X,Y and Z.
For Scaling in OpenGL we have inbuilt function which can be used easily on any 2d or 3d objects. The function is -
Prototype :
void glScaled (GLdouble x,GLdouble y,GLdouble z);
void glScalef (GLfloat x,GLfloat y, GLfloat z);
Sample :
glScalef (GLfloat 1.0f,GLfloat 0.5f , GLfloat 2.0f);
Here, in above sample code we see the function will scale the object into half in y direction, twice in z axis while remain same in x.
One thing is to be note is that - the matrix mode should be either GL_MODELVIEW or GL_PROJECTION, for object to be scaled.
Here is a sample program Which helps you understand the how the scaling works in perspective of Opengl computer graphics. This is simple c program, use x,y,z to scale down and X,Y,Z to increase scale factor in respective axis.
#include <gl/glut.h>
int x1 = 20.0f;
int y1 = 30.0f;
int x2 = 40.0f;
int y2 = 50.0f;
int x3 = 60.0f;
int y3 = 10.0f;
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(x1, y1, 0.0f);
glVertex3f(x2, y2, 0.0f);
glVertex3f(x3, y3, 0.0f);
glEnd( );
glPopMatrix();
glFlush();
}
void MyKeyboard(unsigned char key,int mouseX,int mouseY)
{
if (key == 'x')
{
glScaled (0.5f ,1.0f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'y')
{
glScaled (1.0f ,0.5f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'z')
{
glScaled (1.0f ,1.0f ,0.5f);
glutPostRedisplay();
return;
}
else if (key == 'X')
{
glScaled (1.5f ,1.0f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'Y')
{
glScaled (1.0f ,1.5f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'Z')
{
glScaled (1.0f ,1.0f ,1.5f);
glutPostRedisplay();
return;
}
else
{
glScaled (1.0f ,1.0f ,1.0f);
glutPostRedisplay();
return;
}
}
void main(int argc,char** argr)
{
glutInit(&argc,argr);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1000,600);
glutInitWindowPosition(50,50);
glutCreateWindow("The Scaling");
glutDisplayFunc(Display);
glutKeyboardFunc(MyKeyboard);
glClearColor(0.0f,0.0f,0.0f,0.0f);
gluOrtho2D(0.0,1000.0,0.0,600.0);
glutMainLoop();
}
I think you get to know about the scaling transformation in OpenGL. For any question, query or suggestion put you comments.
For Scaling in OpenGL we have inbuilt function which can be used easily on any 2d or 3d objects. The function is -
Prototype :
void glScaled (GLdouble x,GLdouble y,GLdouble z);
void glScalef (GLfloat x,GLfloat y, GLfloat z);
Sample :
glScalef (GLfloat 1.0f,GLfloat 0.5f , GLfloat 2.0f);
Here, in above sample code we see the function will scale the object into half in y direction, twice in z axis while remain same in x.
One thing is to be note is that - the matrix mode should be either GL_MODELVIEW or GL_PROJECTION, for object to be scaled.
Here is a sample program Which helps you understand the how the scaling works in perspective of Opengl computer graphics. This is simple c program, use x,y,z to scale down and X,Y,Z to increase scale factor in respective axis.
#include <gl/glut.h>
int x1 = 20.0f;
int y1 = 30.0f;
int x2 = 40.0f;
int y2 = 50.0f;
int x3 = 60.0f;
int y3 = 10.0f;
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(x1, y1, 0.0f);
glVertex3f(x2, y2, 0.0f);
glVertex3f(x3, y3, 0.0f);
glEnd( );
glPopMatrix();
glFlush();
}
void MyKeyboard(unsigned char key,int mouseX,int mouseY)
{
if (key == 'x')
{
glScaled (0.5f ,1.0f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'y')
{
glScaled (1.0f ,0.5f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'z')
{
glScaled (1.0f ,1.0f ,0.5f);
glutPostRedisplay();
return;
}
else if (key == 'X')
{
glScaled (1.5f ,1.0f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'Y')
{
glScaled (1.0f ,1.5f ,1.0f);
glutPostRedisplay();
return;
}
else if (key == 'Z')
{
glScaled (1.0f ,1.0f ,1.5f);
glutPostRedisplay();
return;
}
else
{
glScaled (1.0f ,1.0f ,1.0f);
glutPostRedisplay();
return;
}
}
void main(int argc,char** argr)
{
glutInit(&argc,argr);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1000,600);
glutInitWindowPosition(50,50);
glutCreateWindow("The Scaling");
glutDisplayFunc(Display);
glutKeyboardFunc(MyKeyboard);
glClearColor(0.0f,0.0f,0.0f,0.0f);
gluOrtho2D(0.0,1000.0,0.0,600.0);
glutMainLoop();
}
Pls sir mail me the reports cloakrip@gmail.com I have to submit tmrw... and the first page is little blurred how to increase resolution
ReplyDeleteAnd pleased let me know how to include 2 more colour's like red etc
ReplyDeleteThe video is clearly mentioned how to add more colors........... watch it again and again to learn
ReplyDeletePls mail the reports ... yes I learned to add colors nice project pls mail the reports
ReplyDeleteDownload the report and try to make it in your own way for this projects most of the things are common. go to download page
ReplyDeleteOki just send the download link for reports here... just paste in ur comment
ReplyDeleteget it from here http://www.openglprojects.in/p/downloads.html or you see from the menu
ReplyDeleteThe link is not working ... and tmrw I have to submit my reports so kindly send me the reports pls.. asp cloakrip@gmail.com
ReplyDeletesir plzzz can u mail me the code to this id plzz sir
ReplyDeletenikhil.hiremath425@gmail.com
Hey can u plz mail me d source code to my email mfardeen11@gmail.com m not able t download tat from download link
ReplyDeleteWholly how you made this so simple?
ReplyDeleteCan u plz mail the source code to bhavani26b @gmail.com
ReplyDeleteCan u plz mail the source code to suheel11@gmail.com
ReplyDeleteDue to Time We will not able to mail you on the time so kindly download it, link is given at the end of post!
ReplyDeleteIt is very hard to each of you via mail, kindly cooperate
The provided link is not working
ReplyDeletesir can u pls send me the project report for singly linked list as in finding difficulty...pls mail it my email id chekodunpavi17@gmail.com
ReplyDeletethanks in advance sir......
I liked this beautiful fountain
ReplyDeleteCan I have this code to test it and edit on it ?
Mail :
rfrf.my.love@hotmai.com
@Rajeev Kumar Singh see that men !
ReplyDelete"
FLOWING FOUNTAIN
Sorry for this step! but you need to prove you are Human not a Bot
We get so many download requests to stop the auto download via bot or any software we need you to enter the Captcha.
Fill the Captcha and get your requested file
Note any error in dowloading the file please put your comment at desire article so we can fix the issues. Our Source code are free and always will be!
"
Hej. Good project.
ReplyDeletehello sir... can u please explain me the functions used? am not understanding them
ReplyDeletemy email:vishakhawali48@gmail.com