Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GL_CLAMP_TO_EDGE 0x812F
- #include "engine.h"
- #include "cw3Load.h"
- #include "cw2Load.h"
- //-----------------
- using namespace std;
- int Width = 1280, Height = 720;
- int Wi1,He1;
- int FPS = 0,Frames = 0;
- DWORD LastFPS = 0;
- GLuint LoadTexture(char *TexName);
- //GLuint ModTex1; Tex Name!
- cw2Load Img;
- GLuint Texture;
- float angle;
- enum key_state {Release, Press} keyarr[127];
- //---------------------
- float PlayerPosX, PlayerPosY;
- //---------------------
- #pragma region KeyStates+-
- void key(unsigned char key, int x, int y)
- {
- if(key == 'w')keyarr[int('w')] = Press;
- if(key == 'a')keyarr[int('a')] = Press;
- if(key == 32)keyarr[int(32)] = Press;
- if(key == 's')keyarr[int('s')] = Press;
- if(key == 'd')keyarr[int('d')] = Press;
- if(key == 'z')keyarr[int('z')] = Press;
- if(key == 'x')keyarr[int('x')] = Press;
- }
- void keyup(unsigned char key, int x, int y)
- {
- if(key == 'w')keyarr['w'] = Release;
- if(key == 'a')keyarr['a'] = Release;
- if(key == 32)keyarr[32] = Release;
- if(key == 's')keyarr[int('s')] = Release;
- if(key == 'd')keyarr[int('d')] = Release;
- if(key == 'z')keyarr[int('z')] = Release;
- if(key == 'x')keyarr[int('x')] = Release;
- }
- #pragma endregion
- void Draw2DSt(void)
- {
- //For 2D sprites ,textures....
- glViewport(0,0,Width,Height);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- gluOrtho2D(0,Wi1,0,He1);
- glScalef(1,-1,1);
- glTranslatef(0,-He1,0);
- glMatrixMode(GL_MODELVIEW);
- }
- void Draw2DEnd(void)
- {
- //For 3D obj's
- glViewport(0,0,(GLfloat)Width,(GLfloat)Height);
- glMatrixMode(GL_PROJECTION);
- glEnable (GL_DEPTH_TEST);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- }
- void Draw()
- {
- if( keyarr['w'] )
- {
- }
- }
- #pragma region DrawFPSC
- void DrawFPSCT()
- {
- glRasterPos2f(1135,16);
- char stringS[300];
- sprintf_s(stringS, "FPS: %d", FPS);
- for (const char* ch=stringS; *ch != '\0'; ch++)
- {
- glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,*ch);
- }
- if(GetTickCount() -LastFPS >=1000)
- {
- LastFPS = GetTickCount();
- FPS = Frames;
- Frames = 0;
- }
- Frames++;
- }
- #pragma endregion
- void idle()
- {
- glutPostRedisplay();
- }
- void DrawGUI( )
- {
- DrawFPSCT();
- }
- void RenderAll(void)
- {
- Draw();
- glClearColor(0.6f,0.6f,0.6f,1);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- Draw2DSt();
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
- //glBindTexture (GL_TEXTURE_2D,Texture Name);
- //2D sprites
- // glBegin(GL_QUADS);
- // glTexCoord2f(0,1); glVertex2f(3466+0, 460+0);
- // glTexCoord2f(1,1); glVertex2f(3466+362, 460+0);
- // glTexCoord2f(1,0); glVertex2f(3466+362, 460+362);
- // glTexCoord2f(0,0); glVertex2f(3466+0, 460+362);
- // glEnd();
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_DEPTH_TEST);
- DrawGUI();
- Draw2DEnd();
- //3D
- glPushMatrix();
- angle++;
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glTranslatef(0,0,-50);//-100
- glRotatef(angle,0,1,0);
- //----------------------- OBJ* readers ar failu.
- RaDOBJ("ak47.obj");
- //-----------------------
- glFlush();
- glPopMatrix();
- glutSwapBuffers();
- }
- void Res(int w,int h)
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,1000.0f);
- Wi1 = w;
- He1 = h;
- glMatrixMode(GL_MODELVIEW);
- }
- int main(int argc,char* argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
- glutInitWindowSize(Width,Height);
- glutCreateWindow("3D model test");
- glutKeyboardFunc(key);
- glutKeyboardUpFunc(keyup);
- glutIdleFunc(RenderAll);
- glutDisplayFunc(RenderAll);
- glutPostRedisplay();
- glutReshapeFunc(Res);
- //GUI_1 = LoadTexture("data/textures/GUI_1.tga");
- glutMainLoop();
- //glDeleteTextures(1,&GUI_1);
- return 0;
- }
- GLuint LoadTexture(char *TexName)
- {
- if(Img.Load(TexName)!=IMG_APC)
- return -1;
- glGenTextures(1,&Texture);
- glBindTexture(GL_TEXTURE_2D,Texture);
- if(Img.GetBPP()==32)
- glTexImage2D(GL_TEXTURE_2D,0,4,Img.GetWidth(),Img.GetHeight(),0,
- GL_RGBA,GL_UNSIGNED_BYTE,Img.GetImg());
- else
- return -1;
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
- return Texture;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement