Accueil > > > VAISSEAUX ANIMATOR[DEV C++]
VAISSEAUX ANIMATOR[DEV C++]
Information sur la source
Description
C'est juste un début d'application où vous devez tirer sur 2 carrés qui se déplacent tout seul. Le seul vrai intérêt est le code source. Dev C++
Source
- // Includes
-
- #include <windows.h>
- #include <gl/gl.h>
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- // Function Declarations
-
- LRESULT CALLBACK
- WndProc( HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam );
- VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC );
- VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC );
- float carre1X = 0.25f; float carre1Y = 0.25f;
- float carre2X = -0.25f; float carre2Y = -0.25f;
- float carre3X = 0.25f; float carre3Y = -0.25f;
- int nombre; int nombre2; int nombre3;
- int choix, choix2, choix3;
- int hasard = 60; int hasard2 = 60;
- int n = 0;
- int i = 0;
- int a = 0;
- float tir1X[100000]; float tir1Y[100000];
- float tir2X[100000]; float tir2Y[100000];
- float tir3X[100000]; float tir3Y[100000];
- float couleur1 = 0.0f;
- float couleur21 = 1.0f; float couleur22 = 1.0f; float couleur23 = 1.0f;
- float couleur31 = 1.0f; float couleur32 = 1.0f; float couleur33 = 1.0f;
- int indicateur = 0;
- float score = 10.0f;
-
- void shoot(int tir)
- {
- if (tir == 1)
- {
- glBegin(GL_POLYGON);
- glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n], tir1Y[n]);
- glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n] + 0.02f, tir1Y[n]);
- glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n] + 0.02f, tir1Y[n] - 0.05f);
- glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n], tir1Y[n] - 0.05f);
-
- glEnd();
- tir1Y[n] = tir1Y[n] - 0.01f;
- if (tir1X[n] >= carre2X)
- {
- if (tir1X[n] <= carre2X + 0.15f)
- {
- if (tir1Y[n] - 0.05f >= carre2Y + 0.14f)
- {
- if (tir1Y[n] - 0.05f <= carre2Y + 0.15f)
- {
- couleur21 = couleur21 - 0.25f;
- couleur22 = couleur21 - 0.25f;
- couleur23 = couleur21 - 0.25f;
- }
- }
- }
- }
-
- if (tir1X[n] >= carre3X)
- {
- if (tir1X[n] <= carre3X + 0.15f)
- {
- if (tir1Y[n] - 0.05f >= carre3Y + 0.14f)
- {
- if (tir1Y[n] - 0.05f <= carre3Y + 0.15f)
- {
- couleur31 = couleur31 - 0.25f;
- couleur32 = couleur32 - 0.25f;
- couleur33 = couleur33 - 0.25f;
- }
- }
- }
- }
-
- }
- if (tir == 2)
- {
- glBegin(GL_POLYGON);
- glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i], tir2Y[i]);
- glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i] + 0.02f, tir2Y[i]);
- glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i] + 0.02f, tir2Y[i] + 0.05f);
- glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i], tir2Y[i] + 0.05f);
-
- glEnd();
- tir2Y[i] = tir2Y[i] + 0.01f;
- if (tir2X[i] >= carre1X)
- {
- if (tir2X[i] <= carre1X + 0.15f)
- {
- if (tir2Y[i] + 0.05f >= carre1Y)
- {
- if (tir2Y[i] + 0.05f <= carre1Y + 0.1f)
- {
- couleur1 = 1.0f;
- if (indicateur <= 0)
- {
- score = score - 1.0f;
- indicateur = 10;
- }
- }
- }
- }
- }
-
- }
-
- if (tir == 3)
- {
- glBegin(GL_POLYGON);
- glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a], tir3Y[a]);
- glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a] + 0.02f, tir3Y[a]);
- glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a] + 0.02f, tir3Y[a] + 0.05f);
- glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a], tir3Y[a] + 0.05f);
-
- glEnd();
- tir3Y[a] = tir3Y[a] + 0.01f;
- if (tir3X[a] >= carre1X)
- {
- if (tir3X[a] <= carre1X + 0.15f)
- {
- if (tir3Y[a] + 0.05f >= carre1Y)
- {
- if (tir3Y[a] + 0.05f <= carre1Y + 0.1f)
- {
- couleur1 = 1.0f;
- if (indicateur <= 0)
- {
- score = score - 1.0f;
- indicateur = 10;
- }
- }
- }
- }
- }
-
- }
-
-
- }
-
- // WinMain
-
- int WINAPI
- WinMain( HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int iCmdShow )
- {
- srand( (unsigned)time( NULL ) );
- WNDCLASS wc;
- HWND hWnd;
- HDC hDC;
- HGLRC hRC;
- MSG msg;
- BOOL bQuit = FALSE;
- float theta = 0.0f;
- // register window class
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "GLSample";
- RegisterClass( &wc );
-
- // create main window
- hWnd = CreateWindow(
- "GLSample", "OpenGL Sample",
- WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
- 0, 0, 700, 700,
- NULL, NULL, hInstance, NULL );
-
- // enable OpenGL for the window
- EnableOpenGL( hWnd, &hDC, &hRC );
-
- // program main loop
- while ( !bQuit ) {
-
- // check for messages
- if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
-
- // handle or dispatch messages
- if ( msg.message == WM_QUIT ) {
- bQuit = TRUE;
- } else {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
-
- } else {
-
-
- // OpenGL animation code goes here
- glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
- glClear( GL_COLOR_BUFFER_BIT );
- glBegin(GL_POLYGON);
- glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X, carre1Y);
- glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X + 0.15f, carre1Y);
- glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X + 0.15f, carre1Y + 0.15f);
- glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X, carre1Y + 0.15f);
- glEnd();
-
- if (choix == 1)
- {
- shoot(1);
- }
-
- nombre2 = rand() % hasard;
- if (hasard != 60)
- {
- hasard = hasard - 1;
- }
- if (nombre2 == 53)
- {
- hasard = hasard + 40;
- choix2 = 1;
- i = i + 1;
- tir2X[i] = carre2X + 0.075f;
- tir2Y[i] = carre2Y + 0.15f;
- }
-
- if (choix2 == 1)
- {
- shoot(2);
- }
-
- nombre3 = rand() % hasard2;
- if (hasard2 != 60)
- {
- hasard2 = hasard2 - 1;
- }
- if (nombre3 == 53)
- {
- hasard2 = hasard2 + 40;
- choix3 = 1;
- a = a + 1;
- tir3X[a] = carre3X + 0.075f;
- tir2Y[a] = carre3Y + 0.15f;
- }
-
- if (choix3 == 1)
- {
- shoot(3);
- }
-
- glBegin(GL_POLYGON);
- nombre = rand() % 14;
- if (nombre == 0)
- {
- if (carre2Y <= 0.0f)
- {
- carre2Y = carre2Y + 0.05f;
- }
- }
-
- if (nombre == 1)
- {
- if (carre2Y >= -0.9f)
- {
- carre2Y = carre2Y - 0.05f;
- }
- }
-
- if (nombre == 2)
- {
- if (carre2X <= 0.9f)
- {
- carre2X = carre2X + 0.05f;
- }
- }
-
- if (nombre == 3)
- {
- if (carre2X >= -0.9f)
- {
- carre2X = carre2X - 0.05f;
- }
- }
-
- if (nombre == 4)
- {
- if (carre2X <= 0.9f)
- {
- carre2X = carre2X + 0.05f;
- }
- }
-
- if (nombre == 5)
- {
- if (carre2X >= -0.9f)
- {
- carre2X = carre2X - 0.05f;
- }
- }
-
- if (nombre == 6)
- {
- if (carre3X >= -0.9f)
- {
- carre3X = carre3X - 0.05f;
- }
- }
-
- if (nombre == 7)
- {
- if (carre3X >= -0.9f)
- {
- carre3X = carre3X - 0.05f;
- }
- }
-
- if (nombre == 8)
- {
- if (carre3X <= 0.9f)
- {
- carre3X = carre3X + 0.05f;
- }
- }
-
- if (nombre == 9)
- {
- if (carre3X <= 0.9f)
- {
- carre3X = carre3X + 0.05f;
- }
- }
-
- if (nombre == 10)
- {
- if (carre3Y >= -0.9f)
- {
- carre3Y = carre3Y - 0.05f;
- }
- }
-
- if (nombre == 11)
- {
- if (carre3Y <= 0.0f)
- {
- carre3Y = carre3Y + 0.05f;
- }
- }
-
- glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X, carre2Y);
- glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X + 0.15f, carre2Y);
- glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X + 0.15f, carre2Y + 0.15f);
- glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X, carre2Y + 0.15f);
- glEnd();
-
- glBegin(GL_POLYGON);
- glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X, carre3Y);
- glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X + 0.15f, carre3Y);
- glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X + 0.15f, carre3Y + 0.15f);
- glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X, carre3Y + 0.15f);
- glEnd();
-
- glBegin(GL_POLYGON);
- glColor3f(0.5f, 0.5f, 1.0f); glVertex2f(0.50f, 0.80f);
- glColor3f(1.0f, 0.5f, 0.5f); glVertex2f(0.50f + (score / 100) * 5, 0.80f);
- glColor3f(0.5f, 1.0f, 0.5f); glVertex2f(0.50f + (score / 100) * 5, 0.90f);
- glColor3f(1.0f, 0.1f, 0.1f); glVertex2f(0.50f, 0.90f);
- glEnd();
-
- indicateur = indicateur - 1;
- SwapBuffers( hDC );
- }
-
- }
-
- // shutdown OpenGL
- DisableOpenGL( hWnd, hDC, hRC );
-
- // destroy the window explicitly
- DestroyWindow( hWnd );
-
- return msg.wParam;
-
- }
-
-
-
- // Window Procedure
-
- LRESULT CALLBACK
- WndProc( HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam )
- {
-
- switch ( message ) {
-
- case WM_CREATE:
- return 0;
-
- case WM_CLOSE:
- PostQuitMessage( 0 );
- return 0;
-
- case WM_DESTROY:
- return 0;
-
- case WM_KEYDOWN:
- switch ( wParam ) {
-
- case VK_ESCAPE:
- PostQuitMessage( 0 );
- return 0;
-
- case VK_UP:
- if (carre1Y <= 0.9f)
- {
- carre1Y = carre1Y + 0.05f;
- }
- return DefWindowProc( hWnd,
- message, wParam, lParam );
- break;
-
- case VK_DOWN:
- if (carre1Y >= 0.1f)
- {
- carre1Y = carre1Y - 0.05f;
- }
- return DefWindowProc( hWnd,
- message, wParam, lParam );
- break;
-
-
- case VK_LEFT:
- if (carre1X >= -1.0f)
- {
- carre1X = carre1X - 0.05f;
- }
- return DefWindowProc( hWnd,
- message, wParam, lParam );
- break;
-
- case VK_RIGHT:
- if (carre1X <= 0.9f)
- {
- carre1X = carre1X + 0.05f;
- }
- return DefWindowProc( hWnd,
- message, wParam, lParam );
- break;
-
- case VK_SPACE:
- n = n + 1;
- choix = 1;
- tir1X[n] = carre1X + 0.075f;
- tir1Y[n] = carre1Y;
- return DefWindowProc( hWnd,
- message, wParam, lParam );
- break;
- }
- return 0;
-
- default:
- return DefWindowProc( hWnd,
- message, wParam, lParam );
-
- }
-
- }
-
- // Enable OpenGL
-
- VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC )
- {
- PIXELFORMATDESCRIPTOR pfd;
- int iFormat;
-
- // get the device context (DC)
- *hDC = GetDC( hWnd );
-
- // set the pixel format for the DC
- ZeroMemory( &pfd, sizeof( pfd ) );
- pfd.nSize = sizeof( pfd );
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW |
- PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cDepthBits = 16;
- pfd.iLayerType = PFD_MAIN_PLANE;
- iFormat = ChoosePixelFormat( *hDC, &pfd );
- SetPixelFormat( *hDC, iFormat, &pfd );
-
- // create and enable the render context (RC)
- *hRC = wglCreateContext( *hDC );
- wglMakeCurrent( *hDC, *hRC );
-
- }
-
- // Disable OpenGL
-
- VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC )
- {
- wglMakeCurrent( NULL, NULL );
- wglDeleteContext( hRC );
- ReleaseDC( hWnd, hDC );
- }
-
-
// Includes
#include <windows.h>
#include <gl/gl.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
// Function Declarations
LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam );
VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC );
VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC );
float carre1X = 0.25f; float carre1Y = 0.25f;
float carre2X = -0.25f; float carre2Y = -0.25f;
float carre3X = 0.25f; float carre3Y = -0.25f;
int nombre; int nombre2; int nombre3;
int choix, choix2, choix3;
int hasard = 60; int hasard2 = 60;
int n = 0;
int i = 0;
int a = 0;
float tir1X[100000]; float tir1Y[100000];
float tir2X[100000]; float tir2Y[100000];
float tir3X[100000]; float tir3Y[100000];
float couleur1 = 0.0f;
float couleur21 = 1.0f; float couleur22 = 1.0f; float couleur23 = 1.0f;
float couleur31 = 1.0f; float couleur32 = 1.0f; float couleur33 = 1.0f;
int indicateur = 0;
float score = 10.0f;
void shoot(int tir)
{
if (tir == 1)
{
glBegin(GL_POLYGON);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n], tir1Y[n]);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n] + 0.02f, tir1Y[n]);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n] + 0.02f, tir1Y[n] - 0.05f);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(tir1X[n], tir1Y[n] - 0.05f);
glEnd();
tir1Y[n] = tir1Y[n] - 0.01f;
if (tir1X[n] >= carre2X)
{
if (tir1X[n] <= carre2X + 0.15f)
{
if (tir1Y[n] - 0.05f >= carre2Y + 0.14f)
{
if (tir1Y[n] - 0.05f <= carre2Y + 0.15f)
{
couleur21 = couleur21 - 0.25f;
couleur22 = couleur21 - 0.25f;
couleur23 = couleur21 - 0.25f;
}
}
}
}
if (tir1X[n] >= carre3X)
{
if (tir1X[n] <= carre3X + 0.15f)
{
if (tir1Y[n] - 0.05f >= carre3Y + 0.14f)
{
if (tir1Y[n] - 0.05f <= carre3Y + 0.15f)
{
couleur31 = couleur31 - 0.25f;
couleur32 = couleur32 - 0.25f;
couleur33 = couleur33 - 0.25f;
}
}
}
}
}
if (tir == 2)
{
glBegin(GL_POLYGON);
glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i], tir2Y[i]);
glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i] + 0.02f, tir2Y[i]);
glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i] + 0.02f, tir2Y[i] + 0.05f);
glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(tir2X[i], tir2Y[i] + 0.05f);
glEnd();
tir2Y[i] = tir2Y[i] + 0.01f;
if (tir2X[i] >= carre1X)
{
if (tir2X[i] <= carre1X + 0.15f)
{
if (tir2Y[i] + 0.05f >= carre1Y)
{
if (tir2Y[i] + 0.05f <= carre1Y + 0.1f)
{
couleur1 = 1.0f;
if (indicateur <= 0)
{
score = score - 1.0f;
indicateur = 10;
}
}
}
}
}
}
if (tir == 3)
{
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a], tir3Y[a]);
glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a] + 0.02f, tir3Y[a]);
glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a] + 0.02f, tir3Y[a] + 0.05f);
glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(tir3X[a], tir3Y[a] + 0.05f);
glEnd();
tir3Y[a] = tir3Y[a] + 0.01f;
if (tir3X[a] >= carre1X)
{
if (tir3X[a] <= carre1X + 0.15f)
{
if (tir3Y[a] + 0.05f >= carre1Y)
{
if (tir3Y[a] + 0.05f <= carre1Y + 0.1f)
{
couleur1 = 1.0f;
if (indicateur <= 0)
{
score = score - 1.0f;
indicateur = 10;
}
}
}
}
}
}
}
// WinMain
int WINAPI
WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow )
{
srand( (unsigned)time( NULL ) );
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
// register window class
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass( &wc );
// create main window
hWnd = CreateWindow(
"GLSample", "OpenGL Sample",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 700, 700,
NULL, NULL, hInstance, NULL );
// enable OpenGL for the window
EnableOpenGL( hWnd, &hDC, &hRC );
// program main loop
while ( !bQuit ) {
// check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
// handle or dispatch messages
if ( msg.message == WM_QUIT ) {
bQuit = TRUE;
} else {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
} else {
// OpenGL animation code goes here
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_POLYGON);
glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X, carre1Y);
glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X + 0.15f, carre1Y);
glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X + 0.15f, carre1Y + 0.15f);
glColor3f(1.0f, couleur1, 0.0f); glVertex2f(carre1X, carre1Y + 0.15f);
glEnd();
if (choix == 1)
{
shoot(1);
}
nombre2 = rand() % hasard;
if (hasard != 60)
{
hasard = hasard - 1;
}
if (nombre2 == 53)
{
hasard = hasard + 40;
choix2 = 1;
i = i + 1;
tir2X[i] = carre2X + 0.075f;
tir2Y[i] = carre2Y + 0.15f;
}
if (choix2 == 1)
{
shoot(2);
}
nombre3 = rand() % hasard2;
if (hasard2 != 60)
{
hasard2 = hasard2 - 1;
}
if (nombre3 == 53)
{
hasard2 = hasard2 + 40;
choix3 = 1;
a = a + 1;
tir3X[a] = carre3X + 0.075f;
tir2Y[a] = carre3Y + 0.15f;
}
if (choix3 == 1)
{
shoot(3);
}
glBegin(GL_POLYGON);
nombre = rand() % 14;
if (nombre == 0)
{
if (carre2Y <= 0.0f)
{
carre2Y = carre2Y + 0.05f;
}
}
if (nombre == 1)
{
if (carre2Y >= -0.9f)
{
carre2Y = carre2Y - 0.05f;
}
}
if (nombre == 2)
{
if (carre2X <= 0.9f)
{
carre2X = carre2X + 0.05f;
}
}
if (nombre == 3)
{
if (carre2X >= -0.9f)
{
carre2X = carre2X - 0.05f;
}
}
if (nombre == 4)
{
if (carre2X <= 0.9f)
{
carre2X = carre2X + 0.05f;
}
}
if (nombre == 5)
{
if (carre2X >= -0.9f)
{
carre2X = carre2X - 0.05f;
}
}
if (nombre == 6)
{
if (carre3X >= -0.9f)
{
carre3X = carre3X - 0.05f;
}
}
if (nombre == 7)
{
if (carre3X >= -0.9f)
{
carre3X = carre3X - 0.05f;
}
}
if (nombre == 8)
{
if (carre3X <= 0.9f)
{
carre3X = carre3X + 0.05f;
}
}
if (nombre == 9)
{
if (carre3X <= 0.9f)
{
carre3X = carre3X + 0.05f;
}
}
if (nombre == 10)
{
if (carre3Y >= -0.9f)
{
carre3Y = carre3Y - 0.05f;
}
}
if (nombre == 11)
{
if (carre3Y <= 0.0f)
{
carre3Y = carre3Y + 0.05f;
}
}
glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X, carre2Y);
glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X + 0.15f, carre2Y);
glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X + 0.15f, carre2Y + 0.15f);
glColor3f(couleur21, couleur22, couleur23); glVertex2f(carre2X, carre2Y + 0.15f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X, carre3Y);
glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X + 0.15f, carre3Y);
glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X + 0.15f, carre3Y + 0.15f);
glColor3f(couleur31, couleur32, couleur33); glVertex2f(carre3X, carre3Y + 0.15f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.5f, 0.5f, 1.0f); glVertex2f(0.50f, 0.80f);
glColor3f(1.0f, 0.5f, 0.5f); glVertex2f(0.50f + (score / 100) * 5, 0.80f);
glColor3f(0.5f, 1.0f, 0.5f); glVertex2f(0.50f + (score / 100) * 5, 0.90f);
glColor3f(1.0f, 0.1f, 0.1f); glVertex2f(0.50f, 0.90f);
glEnd();
indicateur = indicateur - 1;
SwapBuffers( hDC );
}
}
// shutdown OpenGL
DisableOpenGL( hWnd, hDC, hRC );
// destroy the window explicitly
DestroyWindow( hWnd );
return msg.wParam;
}
// Window Procedure
LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam )
{
switch ( message ) {
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage( 0 );
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch ( wParam ) {
case VK_ESCAPE:
PostQuitMessage( 0 );
return 0;
case VK_UP:
if (carre1Y <= 0.9f)
{
carre1Y = carre1Y + 0.05f;
}
return DefWindowProc( hWnd,
message, wParam, lParam );
break;
case VK_DOWN:
if (carre1Y >= 0.1f)
{
carre1Y = carre1Y - 0.05f;
}
return DefWindowProc( hWnd,
message, wParam, lParam );
break;
case VK_LEFT:
if (carre1X >= -1.0f)
{
carre1X = carre1X - 0.05f;
}
return DefWindowProc( hWnd,
message, wParam, lParam );
break;
case VK_RIGHT:
if (carre1X <= 0.9f)
{
carre1X = carre1X + 0.05f;
}
return DefWindowProc( hWnd,
message, wParam, lParam );
break;
case VK_SPACE:
n = n + 1;
choix = 1;
tir1X[n] = carre1X + 0.075f;
tir1Y[n] = carre1Y;
return DefWindowProc( hWnd,
message, wParam, lParam );
break;
}
return 0;
default:
return DefWindowProc( hWnd,
message, wParam, lParam );
}
}
// Enable OpenGL
VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC )
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
// get the device context (DC)
*hDC = GetDC( hWnd );
// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( *hDC, &pfd );
SetPixelFormat( *hDC, iFormat, &pfd );
// create and enable the render context (RC)
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}
// Disable OpenGL
VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC )
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}
Conclusion
sous la suggestion de Jo (commentaire plus bas), je précise le compilateur : Dev C++. Pour compiler la source, il faut créer un project .dev et mettre la source dans un fichier .cpp
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|