here is my code
#include <freeglut.h>
#include <iostream>
#include <SOIL.h>
//#include "glui.h"
using namespace std;
GLuint texture[8];
float move_x = 0.0f, move_y = 0.0f;
int turn_tank = 0;
void Land_Outline()
{
glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(2.0f);
glBegin(GL_LINE_STRIP);
glVertex3f(135.0f, -100.0f, 0.0f);
glVertex3f(115.0f, -80.0f, 0.0f);
glVertex3f(90.0f, -80.0f, 0.0f);
glVertex3f(80.0f, -60.0f, 0.0f);
glVertex3f(50.0f, -60.0f, 0.0f);
glVertex3f(30.0f, -30.0f, 0.0f);
glVertex3f(10.0f, -30.0f, 0.0f);
glVertex3f(-20.0f, 0.0f, 0.0f);
glVertex3f(-50.0f, 0.0f, 0.0f);
glVertex3f(-70.0f, -20.0f, 0.0f);
glVertex3f(-100.0f, -20.0f, 0.0f);
glVertex3f(-120.0f, -40.0f, 0.0f);
glVertex3f(-133.0f, -100.0f, 0.0f);
glEnd();
}
void Player_Tank()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_POLYGON);
glTexCoord3f(0.0f, 0.0f, 0.0f);
glVertex3f(115.0f + move_x, -80.0f + move_y, 0.0f);
glTexCoord3f(1.0f, 0.0f, 0.0f);
glVertex3f(135.0f + move_x, -100.0f + move_y, 0.0f);
glTexCoord3f(1.0f, 1.0f, 0.0f);
glVertex3f(145.0f + move_x, -90.0f + move_y, 0.0f);
glTexCoord3f(0.0f, 1.0f, 0.0f);
glVertex3f(125.0f + move_x, -70.0f + move_y, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void Player_Tank_two()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_POLYGON);
glTexCoord3f(0.0f, 0.0f, 0.0f);
glVertex3f(110.0f + move_x, -90.0f + move_y, 0.0f);
glTexCoord3f(1.0f, 0.0f, 0.0f);
glVertex3f(130.0f + move_x, -90.0f + move_y, 0.0f);
glTexCoord3f(1.0f, 1.0f, 0.0f);
glVertex3f(130.0f + move_x, -80.0f + move_y, 0.0f);
glTexCoord3f(0.0f, 1.0f, 0.0f);
glVertex3f(110.0f + move_x, -80.0f + move_y, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
}
GLuint loadTex(const char *texname)
{
/* load an image file directly as a new OpenGL texture */
GLuint texture = SOIL_load_OGL_texture
(
texname,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
);
return texture;
}
void init()
{
texture[0] = loadTex("C:\\Users\\Owner\\Desktop\\tanksprite.png");
}
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT);
if (turn_tank == 0)
{
Player_Tank();
}
if (turn_tank == 1)
{
Player_Tank_two();
}
Land_Outline();
glFinish();
}
void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat aspectRatio;
if (h == 0)
h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho(-100.0, 100.0, -100.0 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
else
glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void handleKeypress(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
case 32:
break;
}
glutPostRedisplay();
}
void handleSpecialKeypress(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_LEFT:
if (move_y <= -24)
{
move_y++;
turn_tank = 0;
move_x = -24;
}
else if (move_x <= -11 && move_y >= 11)
{
turn_tank = 1;
move_y = 11;
move_x--;
}
cout << move_x << " " << move_y << endl;
move_x--;
move_y++;
break;
case GLUT_KEY_RIGHT:
move_x++;
move_y--;
if (move_x >= 0 && move_y <= 0)
{
move_x = 0;
move_y = 0;
}
break;
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
}
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(600, 300);
glutInitWindowSize(800, 600);
glutCreateWindow("ScorchedEarth");
glutKeyboardFunc(handleKeypress);
glutSpecialFunc(handleSpecialKeypress);
glutDisplayFunc(renderScene);
glutReshapeFunc(ChangeSize);
init();
glutMainLoop();
return 0;
}