Neomex01
12-07-2010, 09:32 AM
Hello, I'm making a 2d game, and I think it's good moment now to say that I've got completly no experience coding in OpenGL, however I've read lot of stuff about how all this works...
My first question is:
What is the easiest way to move object, and what is known in OpenGL as 'object' ?
Thats my code:
#include <glut.h>
void displayCB(void) /* function called whenever redisplay needed */
{
glClear(GL_COLOR_BUFFER_BIT); /* clear the display */
glColor3f(1.0, 1.0, 1.0); /* set current color to white */
glBegin(GL_POLYGON); /* draw filled triangle */
glVertex2i(0,0); /* specify each vertex of triangle */
glVertex2i(800,0);
glVertex2i(300,300);
glEnd(); /* OpenGL draws the filled triangle */
glFlush(); /* Complete any pending operations */
}
void keyCB(unsigned char key, int x, int y) /* called on key press */
{
if( key == 'q' ) exit(0);
}
GLvoid Timer( int value )
{
if( value ) glutPostRedisplay();
glutTimerFunc(40,Timer,value);
}
int main(int argc, char *argv[])
{
int win;
glutInit(&argc, argv); /* initialize GLUT system */
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(800,600); /* width=400pixels height=500pixels */
win = glutCreateWindow("Triangle"); /* create window */
/* from this point on the current window is win */
glClearColor(0.0,0.0,0.0,0.0); /* set background to black */
gluOrtho2D(0,800,0,600); /* how object is mapped to window */
glutDisplayFunc(displayCB); /* set window's display callback */
glutTimerFunc(40,Timer,0);
glutKeyboardFunc(keyCB); /* set window's key callback */
glutMainLoop(); /* start processing events... */
/* execution never reaches this point */
return 0;
}
and I want to move this triangle, how to do this?
What glut(smthing)Func (like glutKeyboardFunc()) which may be usefull I'm missing?
How to do double buffering in 2D project like mine?
And what is the easiest way to texture this triangle? I have to write whole file loading function?
I will be really thankfull for any help.
My first question is:
What is the easiest way to move object, and what is known in OpenGL as 'object' ?
Thats my code:
#include <glut.h>
void displayCB(void) /* function called whenever redisplay needed */
{
glClear(GL_COLOR_BUFFER_BIT); /* clear the display */
glColor3f(1.0, 1.0, 1.0); /* set current color to white */
glBegin(GL_POLYGON); /* draw filled triangle */
glVertex2i(0,0); /* specify each vertex of triangle */
glVertex2i(800,0);
glVertex2i(300,300);
glEnd(); /* OpenGL draws the filled triangle */
glFlush(); /* Complete any pending operations */
}
void keyCB(unsigned char key, int x, int y) /* called on key press */
{
if( key == 'q' ) exit(0);
}
GLvoid Timer( int value )
{
if( value ) glutPostRedisplay();
glutTimerFunc(40,Timer,value);
}
int main(int argc, char *argv[])
{
int win;
glutInit(&argc, argv); /* initialize GLUT system */
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(800,600); /* width=400pixels height=500pixels */
win = glutCreateWindow("Triangle"); /* create window */
/* from this point on the current window is win */
glClearColor(0.0,0.0,0.0,0.0); /* set background to black */
gluOrtho2D(0,800,0,600); /* how object is mapped to window */
glutDisplayFunc(displayCB); /* set window's display callback */
glutTimerFunc(40,Timer,0);
glutKeyboardFunc(keyCB); /* set window's key callback */
glutMainLoop(); /* start processing events... */
/* execution never reaches this point */
return 0;
}
and I want to move this triangle, how to do this?
What glut(smthing)Func (like glutKeyboardFunc()) which may be usefull I'm missing?
How to do double buffering in 2D project like mine?
And what is the easiest way to texture this triangle? I have to write whole file loading function?
I will be really thankfull for any help.