PDA

View Full Version : translatef



angel111
04-22-2011, 07:35 AM
hi....here s my simple code for a cube...
pls show me how to move to horizontally n continuously using translatef();


pls help me:(

angel111
04-22-2011, 07:37 AM
#include<windows.h>
#include<GL/glut.h>
#include<stdio.h>

void Init()
{
glClearColor(0.0,0.0,0.0,0.0);
gluOrtho2D(0.0,50.0,0.0,50.0);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(5.0,5.0);
glVertex2f(10.0,5.0);
glVertex2f(10.0,15.0);
glVertex2f(5.0,15.0);
glEnd();


glFlush();
}




void main(int argc,char **argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("");
glutDisplayFunc(display);
Init();
glutMainLoop();
}

BionicBytes
04-22-2011, 02:22 PM
What is there to say? Use a variable for horizonal and vertical position and plug into glTranslatef. Use glPushmatrix and glPopmatrix before and after drawing the cube. Once modelview matrix has been pushed you can issue glTranslatef just before the cube draw.