• Benvenuto in Making Videogames!
  • Dai sfogo alla tua fantasia!
  • Crea il tuo Videogioco!
Benvenuto ospite! Login Registrati




Valutazione discussione:
  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5
Configurare le OpenGL in Visual C++ Express 2010/2008
#1
Una piccola guida per configurare le OpenGL in Visual C++ Express
2010/2008.

Creare un nuovo progetto:
  1. Apriamo Visual C++
  2. File > Nuova > Progetto
  3. Progetto Win32
  4. Scegliete il nome del progetto
  5. Cliccate su: Ok
  6. Cliccate su: Avanti
  7. Spuntate la casella: Progetto vuoto
  8. Cliccate: Fine

Configurare il progetto per le OpenGL:
  1. Testo destro sul progetto
  2. Proprietà > Proprietà di configurazione > Linker > Input
  3. Ora andate all'estremità delle: Dipende Aggiuntive e cliccate sulla freccetta che punta in basso > Modifica
  4. Ora aggiungete: glu32.lib opengl32.lib
  5. Cliccate su Ok

Creiamo il file .cpp:
  1. Cliccate sull'icona che c'è sotto la voce menù: Modifica
  2. Selezionare il file .cpp e dargli un nome
  3. Cliccate su Aggiungi

Ora per vedere se tutto funziona, vi posto il source di un file .cpp trovato su internet, se non erro, è della guida NeHe dove spiega le OpenGL.

Codice PHP:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>

HWND    hWnd;
HDC     hDC;
HGLRC   hRC;

// Set up pixel format for graphics initialization
void SetupPixelFormat()
{
    
PIXELFORMATDESCRIPTOR pfd, *ppfd;
    
int pixelformat;

    
ppfd = &pfd;

    
ppfd->nSize sizeof(PIXELFORMATDESCRIPTOR);
    
ppfd->nVersion 1;
    
ppfd->dwFlags PFD_DRAW_TO_WINDOW PFD_SUPPORT_OPENGL PFD_DOUBLEBUFFER;
    
ppfd->dwLayerMask PFD_MAIN_PLANE;
    
ppfd->iPixelType PFD_TYPE_COLORINDEX;
    
ppfd->cColorBits 16;
    
ppfd->cDepthBits 16;
    
ppfd->cAccumBits 0;
    
ppfd->cStencilBits 0;

    
pixelformat ChoosePixelFormat(hDCppfd);
    
SetPixelFormat(hDCpixelformatppfd);
}

// Initialize OpenGL graphics
void InitGraphics()
{
    
hDC GetDC(hWnd);

    
SetupPixelFormat();

    
hRC wglCreateContext(hDC);
    
wglMakeCurrent(hDChRC);

    
glClearColor(0000.5);
    
glClearDepth(1.0);
    
glEnable(GL_DEPTH_TEST);
}

// Resize graphics to fit window
void ResizeGraphics()
{
    
// Get new window size
    
RECT rect;
    
int widthheight;
    
GLfloat aspect;

    
GetClientRect(hWnd, &rect);
    
width rect.right;
    
height rect.bottom;
    
aspect = (GLfloat)width height;

    
// Adjust graphics to window size
    
glViewport(00widthheight);
    
glMatrixMode(GL_PROJECTION);
    
glLoadIdentity();
    
gluPerspective(45.0aspect1.0100.0);
    
glMatrixMode(GL_MODELVIEW);
}

// Draw frame
void DrawGraphics()
{
    
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);

    
// Set location in front of camera
    
glLoadIdentity();
    
glTranslated(00, -10);

    
// Draw a square
    
glBegin(GL_QUADS);
    
glColor3d(100);
    
glVertex3d(-220);
    
glVertex3d(220);
    
glVertex3d(2, -20);
    
glVertex3d(-2, -20);
    
glEnd();

    
// Show the new scene
    
SwapBuffers(hDC);
}

// Handle window events and messages
LONG WINAPI MainWndProc (HWND hWndUINT uMsgWPARAM  wParamLPARAM  lParam)
{
    switch (
uMsg)
    {
    case 
WM_SIZE:
        
ResizeGraphics();
        break;

    case 
WM_CLOSE
        
DestroyWindow(hWnd);
        break;
 
    case 
WM_DESTROY:
        
PostQuitMessage(0);
        break;
 
    
// Default event handler
    
default: 
        return 
DefWindowProc (hWnduMsgwParamlParam); 
        break; 
    } 
 
    return 
1
}

int WINAPI WinMain (HINSTANCE hInstanceHINSTANCE hPrevInstanceLPSTR lpCmdLineint nCmdShow)
{

    const 
LPCWSTR appname TEXT("OpenGL Sample");

    
WNDCLASS wndclass;
    
MSG      msg;
 
    
// Define the window class
    
wndclass.style         0;
    
wndclass.lpfnWndProc   = (WNDPROC)MainWndProc;
    
wndclass.cbClsExtra    0;
    
wndclass.cbWndExtra    0;
    
wndclass.hInstance     hInstance;
    
wndclass.hIcon         LoadIcon(hInstanceappname);
    
wndclass.hCursor       LoadCursor(NULL,IDC_ARROW);
    
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    
wndclass.lpszMenuName  appname;
    
wndclass.lpszClassName appname;
 
    
// Register the window class
    
if (!RegisterClass(&wndclass)) return FALSE;
 
    
// Create the window
    
hWnd CreateWindow(
            
appname,
            
appname,
            
WS_OVERLAPPEDWINDOW WS_CLIPSIBLINGS WS_CLIPCHILDREN,
            
CW_USEDEFAULT,
            
CW_USEDEFAULT,
            
800,
            
600,
            
NULL,
            
NULL,
            
hInstance,
            
NULL);
 
    if (!
hWnd) return FALSE;

    
// Initialize OpenGL
    
InitGraphics();

    
// Display the window
    
ShowWindow(hWndnCmdShow);
    
UpdateWindow(hWnd);

    
// Event loop
    
while (1)
    {
        if (
PeekMessage(&msgNULL00PM_NOREMOVE) == TRUE)
        {
            if (!
GetMessage(&msgNULL00)) return TRUE;

            
TranslateMessage(&msg);
            
DispatchMessage(&msg);
        }
        
DrawGraphics();
    }

    
wglDeleteContext(hRC);
    
ReleaseDC(hWndhDC);


Copiatelo, o meglio ancora copiatelo scrivendolo nel vostro file .cpp e avviate il Deburg, e vi dovrebbe mostrare un finestra con un quadrato rosso con sfondo nero.
 
Rispondi
  


Discussioni simili
Discussione Autore Risposte Letto Ultimo messaggio
  Visual Studio [C#] Export Pinghie 2 1,011 06-09-2015, 12:58 PM
Ultimo messaggio: Pinghie
  Bisogno di una guida per il Visual C# samuele55598@gmail.com 1 1,095 23-01-2014, 09:55 PM
Ultimo messaggio: WilSoft90
  OpenGL Projection Matrix Lorenz 2 1,334 04-06-2013, 07:25 PM
Ultimo messaggio: Lorenz
Question [Visual C#] Non va l'installazione Loryea 6 1,621 18-07-2012, 06:06 PM
Ultimo messaggio: Loryea
  Guida OpenGL per C++ Riddick 4 2,902 20-04-2012, 08:21 PM
Ultimo messaggio: ferrass
  Download Visual Studio 2010 Professional Riddick 4 1,345 11-03-2011, 02:41 PM
Ultimo messaggio: steve
  Microsoft Visual Studio 2010 Ultimate federico 4 1,119 28-01-2011, 08:21 PM
Ultimo messaggio: federico
  Consigliatemi un'alternativa a visual studio Riddick 2 1,799 11-08-2010, 12:49 AM
Ultimo messaggio: Riddick
  Le alternative a visual c++ e visual c# Riddick 0 912 07-07-2010, 03:21 PM
Ultimo messaggio: Riddick
  Scaricare l'intero set di visual c/c++/c# .net Riddick 2 978 27-05-2010, 10:07 AM
Ultimo messaggio: Riddick

Vai al forum:


Browsing: 1 Ospite(i)