begin process at 2012 05 27 17:49:56
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > POLYGONES DIVERSES SANS GLUT[DEV C++...]

POLYGONES DIVERSES SANS GLUT[DEV C++...]


 Information sur la source

Note :
Aucune note
Catégorie :OpenGL Niveau :Débutant Date de création :16/04/2002 Date de mise à jour :16/04/2002 15:58:06 Vu / téléchargé :5 901 / 134

Auteur : mastave

Ecrire un message privé
Site perso
Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

 Description

Différents exemples de plygones en gl/glu

Source

  • #include <windows.h>
  • #include <gl/gl.h>
  • #include <gl/glu.h>
  • WNDCLASS wc;
  • MSG msg;
  • HWND hWnd;
  • HDC DC;
  • HGLRC RC;
  • void RePaint ()
  • {
  • glClear (GL_COLOR_BUFFER_BIT);
  • glMatrixMode (GL_MODELVIEW);
  • glLoadIdentity ();
  • gluLookAt (0,0,-10,0,0,0,0,1,0);
  • glBegin (GL_POLYGON);
  • glColor3d (0,0,1);
  • glVertex2i (-5,-2);
  • glVertex2i (-5,0);
  • glVertex2i (-4,1);
  • glVertex2i (-3,0);
  • glVertex2i (-3,-2);
  • glVertex2i (-4,-3);
  • glEnd ();
  • glBegin (GL_QUADS);
  • glColor3d (1,1,0);
  • glVertex2i (2,2);
  • glVertex2i (2,4);
  • glVertex2i (4,4);
  • glVertex2i (4,2);
  • glEnd ();
  • glBegin (GL_TRIANGLES);
  • glColor3d (0,1,0);
  • glVertex2i (3,-4);
  • glVertex2i (1,-2);
  • glVertex2i (1,-4);
  • glEnd ();
  • glBegin (GL_LINES);
  • glColor3d (1,0,1);
  • glVertex2i (1,1);
  • glVertex2i (-1,-1);
  • glEnd ();
  • SwapBuffers (DC);
  • }
  • void InitPixelFormat (HDC hDC)
  • {
  • PIXELFORMATDESCRIPTOR pfd =
  • {
  • sizeof (PIXELFORMATDESCRIPTOR),
  • 1,
  • PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,
  • 16,
  • 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  • 16,
  • 0, 0, 0, 0, 0, 0, 0
  • };
  • SetPixelFormat (hDC, ChoosePixelFormat (hDC, &pfd), &pfd);
  • }
  • LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  • {
  • switch (uMsg)
  • {
  • case WM_CREATE:
  • DC=GetDC (hwnd);
  • InitPixelFormat (DC);
  • RC = wglCreateContext (DC);
  • wglMakeCurrent (DC, RC);
  • break;
  • case WM_CLOSE:
  • wglMakeCurrent (NULL, NULL);
  • wglDeleteContext (RC);
  • ReleaseDC (hwnd,DC);
  • PostQuitMessage (0);
  • break;
  • case WM_SIZE:
  • glViewport (0,0,LOWORD (lParam),HIWORD (lParam));
  • glMatrixMode (GL_PROJECTION);
  • glLoadIdentity ();
  • gluPerspective (45,(float)(LOWORD(lParam))/(float)(HIWORD(lParam)),1,100);
  • break;
  • case WM_PAINT:
  • RePaint ();
  • break;
  • default:
  • return DefWindowProc (hwnd,uMsg,wParam,lParam);
  • break;
  • }
  • return 0;
  • }
  • int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
  • {
  • wc.style = CS_OWNDC;
  • wc.lpfnWndProc = WindowProc;
  • 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(LTGRAY_BRUSH);
  • wc.lpszMenuName = NULL;
  • wc.lpszClassName = "OGL";
  • RegisterClass(&wc);
  • hWnd = CreateWindow
  • ("OGL", "Fenetre OpenGL",
  • WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
  • 0, 0, 640, 480, NULL, NULL, hInstance, NULL
  • );
  • while (GetMessage(&msg, NULL, 0, 0)) {
  • TranslateMessage(&msg);
  • DispatchMessage(&msg);
  • }
  • return 0;
  • }
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>

WNDCLASS wc;
MSG msg;
HWND hWnd;
HDC	DC;
HGLRC RC;

void RePaint ()
{
	glClear (GL_COLOR_BUFFER_BIT);
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();

    gluLookAt (0,0,-10,0,0,0,0,1,0);

    glBegin (GL_POLYGON);
            glColor3d (0,0,1);
            glVertex2i (-5,-2);
            glVertex2i (-5,0);
            glVertex2i (-4,1);
            glVertex2i (-3,0);
            glVertex2i (-3,-2);
            glVertex2i (-4,-3);
    glEnd ();

    glBegin (GL_QUADS);
            glColor3d (1,1,0);
            glVertex2i (2,2);
            glVertex2i (2,4);
            glVertex2i (4,4);
            glVertex2i (4,2);
    glEnd ();

    glBegin (GL_TRIANGLES);
            glColor3d (0,1,0);
            glVertex2i (3,-4);
            glVertex2i (1,-2);
            glVertex2i (1,-4);
    glEnd ();

    glBegin (GL_LINES);
            glColor3d (1,0,1);
            glVertex2i (1,1);
            glVertex2i (-1,-1);
    glEnd ();

	SwapBuffers (DC);
}

void InitPixelFormat (HDC hDC)
{
      PIXELFORMATDESCRIPTOR pfd =
      {
           sizeof (PIXELFORMATDESCRIPTOR),
           1,
           PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,
           16,
           0, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0,
           16,
           0, 0, 0, 0, 0, 0, 0
      };

      SetPixelFormat (hDC, ChoosePixelFormat (hDC, &pfd), &pfd);
}

LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_CREATE:
		DC=GetDC (hwnd);
        InitPixelFormat (DC);
        RC = wglCreateContext (DC);
        wglMakeCurrent (DC, RC);
		break;
	case WM_CLOSE:
        wglMakeCurrent (NULL, NULL);
        wglDeleteContext (RC);
        ReleaseDC (hwnd,DC);
		PostQuitMessage (0);
		break;
    case WM_SIZE:
    	glViewport (0,0,LOWORD (lParam),HIWORD (lParam));
    	glMatrixMode (GL_PROJECTION);
    	glLoadIdentity ();
    	gluPerspective (45,(float)(LOWORD(lParam))/(float)(HIWORD(lParam)),1,100);
    	break;
    case WM_PAINT:
    	RePaint ();
    	break;
	default:
		return DefWindowProc (hwnd,uMsg,wParam,lParam);
		break;
	}
	return 0;
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WindowProc;
	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(LTGRAY_BRUSH);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "OGL";
	
	RegisterClass(&wc);

	hWnd = CreateWindow
	("OGL", "Fenetre OpenGL",
	WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
	0, 0, 640, 480, NULL, NULL, hInstance, NULL
	);

	while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
} 


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture .::MATRIX::. [DEV C++]
Source avec Zip ANIMATION D'UN CERCLE AVEC TOUCHES + FILM[2D][DEVC++4][GLUT]
FONCTION MENU AVEC FLÈCHES EN MODE TEXTE[DEV C++]
(-:FONCTION TABLEAU EN MODE TEXTE![DEV C++]
FONCTION RECTANGLE COULEUR EN MODE TEXTE[DEV C++]

 Sources de la même categorie

Source avec Zip Source avec une capture AFFICHER DES COURBES DE BEZIER par shorzy
Source avec Zip Source avec une capture BASE/MOTEUR 3D EN QT/OPENGL (COMPLET ET FONCTIONNEL!) POUR U... par envi33
Source avec Zip Source avec une capture CLASSE AVEC OPENGL - OBJETS 3D ET ANIMATIONS par rasta63
Source avec Zip Source avec une capture LETTRES 3D AVEC OPENGL ET QT par opossum_farceur
Source avec Zip CUBE 3D GLUT32 VC++ ET DEVC++ par bobby03

Commentaires et avis

Commentaire de nycos62 le 19/03/2003 12:58:10

j'ai l'impression qu'il me maque les bibliothèques gl pour compiler ce code, voici la liste des erreurs quand je le compile:
--------------------Configuration: nono - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol __imp__glEnd@0
main.obj : error LNK2001: unresolved external symbol __imp__glVertex2i@8
main.obj : error LNK2001: unresolved external symbol __imp__glColor3d@24
main.obj : error LNK2001: unresolved external symbol __imp__glBegin@4
main.obj : error LNK2001: unresolved external symbol _gluLookAt@72
main.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
main.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
main.obj : error LNK2001: unresolved external symbol __imp__glClear@4
main.obj : error LNK2001: unresolved external symbol _gluPerspective@32
main.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
main.obj : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
main.obj : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
main.obj : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/nono.exe : fatal error LNK1120: 14 unresolved externals
Error executing link.exe.

nono.exe - 15 error(s), 0 warning(s)

que faudrait-il faire pour qu'il fonctionnne ?

Commentaire de BenjaminRare le 03/05/2003 03:30:40

Il faut que tu ailles dans Projects-&gt;Settings-&gt;Links and ajoute les bibliotheques suivantes: glu32.lib, glut32.lib et opengl32.lib

ca devrait marcher ....

Commentaire de albert0 le 01/06/2003 20:34:53

LoL ce truc n'est meme pas de TOI

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,452 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales