Can anyone get this to work ?

This is a discussion on Can anyone get this to work ? within the C++ Programming forums, part of the General Programming Boards category; if you get this to work can you tell me which compiler u used ? Code: // Includes #include <windows.h> ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    27

    Can anyone get this to work ?

    if you get this to work can you tell me which compiler u used ?

    Code:
    // Includes
    
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glaux.h>
    
    float angle = 0.0f;
    HDC g_HDC;
    
    void SetupPixelFormat(HDC hDC)
    {
    int nPixelFormat;
    
    static PIXELFORMATDESCRIPTOR pfd= {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW |
    PFD_SUPPORT_OPENGL |
    PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    32,
    0,0,0,0,0,0,
    0,
    0,
    0,
    0,0,0,0,
    16,
    0,
    0,
    PFD_MAIN_PLANE,
    0,
    0,0,0 };
    
    nPixelFormat = ChoosePixelFormat(hDC, &pfd);
    
    SetPixelFormat(hDC, nPixelFormat, &pfd);
    }
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static HGLRC hRC;
    static HDC hDC;
    char string[] = "Hello World";
    int width, height;
    
    switch (message)
    {
    case WM_CREATE:
         hDC = GetDC(hwnd);
         g_HDC = hDC;
         SetupPixelFormat(hDC);
    
         hRC = wglCreateContext(hDC);
         wglMakeCurrent(hDC, hRC);
    
         return 0;
         break;
    
         case WM_CLOSE:
    
         wglMakeCurrent(hDC, NULL);
         wglDeleteContext(hRC);
    
         PostQuitMessage(0);
         return 0;
         break;
    
         case WM_SIZE:
         height = HIWORD(lParam);
         width = LOWORD(lParam);
    
         if (height == 0)
             {
             height = 1;
             }
          glViewport(0,0,width,height);
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
    
          gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
    
          glMatrixMode(GL_MODELVIEW);
          glLoadIdentity();
    
          return 0;
          break;
    
          default:
          break;
     }
      return (DefWindowProc(hwnd, message, wParam, lParam));
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    WNDCLASSEX windowClass;
    HWND hwnd;
    MSG msg;
    bool done;
    
    windowClass.cbSize = sizeof(WNDCLASSEX);
    windowClass.style = CS_HREDRAW | CS_VREDRAW;
    windowClass.lpfnWndProc = WndProc;
    windowClass.cbClsExtra = 0;
    windowClass.cbWndExtra = 0;
    windowClass.hInstance = hInstance;
    windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    windowClass.hbrBackground = NULL;
    windowClass.lpszMenuName = NULL;
    windowClass.lpszClassName = "MyClass";
    windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    
    if (!RegisterClassEx(&windowClass))
    return 0;
    
    hwnd = CreateWindowEx(NULL,"MyClass","The opengl Window Application",WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPSIBLINGS, 100,100,400,400,NULL,NULL,hInstance,NULL);
    
    if (!hwnd)
    return 0;
    
    
    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);
    
    done = false;
    
    while (!done)
    {
    PeekMessage(&msg, hwnd,NULL,NULL, PM_REMOVE);
    
    if (msg.message == WM_QUIT)
    {
    done = true;
    }
    else
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    
    angle = angle + 0.1f;
    if (angle >= 360.0f)
       angle = 0.0f;
    glTranslatef(0.0f,0.0f,-5.0f);
    glRotatef(angle,0.0f,0.0f,1.0f);
    
    glColor3f(1.0f,0.0f,0.0f);
    glBegin(GL_TRIANGLES);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(1.0f,0.0f,0.0f);
    glVertex3f(1.0f,1.0f,0.0f);
    
    glEnd();
    
    SwapBuffers(g_HDC);
    
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }
    return msg.wParam;
    }

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    9

    15 errors in MSVC6

    I tried to compile this program in Visual C++ 6 and i get 15 errors during the linking stage. It says there are 14 unresolved external symbols. I'm not sure if this problem is specifically with my compiler or not, but basically I couldn't get the program to compile.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    27
    you have to include the libraries under project options(glu32.lib, glaux.lib, opengl32.lib)

  4. #4
    Registered User Liam Battle's Avatar
    Join Date
    Jan 2002
    Posts
    114
    you need to include them into ur lib under your compiler options
    LB0: * Life once school is done
    LB1: N <- WakeUp;
    LB2: N <- C++_Code;
    LB3: N >= Tired : N <- Sleep;
    LB4: JMP*-3;

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    9

    Program works

    Thanks for the help. I just wanted to let the person who posted the code know that the program works in MSVC++ 6.0.

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    49
    I compiled it with VC6 and saw a red triangle in a black window...

    you should add glu32.lib and opengl32.lib to your link list.
    Hello, everyone.

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    27
    I keep getting this message with the same code:

    --------------------Configuration: sw - Win32 Debug--------------------
    Compiling...
    sw.cpp
    c:\program files\microsoft visual studio\myprojects\sw\sw.cpp(164) : fatal error C1010: unexpected end of file while looking for precompiled header directive
    Error executing cl.exe.

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    49
    Add a line as your FIRST line:

    #include "stdafx.h"

    NOTE: this line must be first valid line for precompile header files to work.
    Hello, everyone.

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    27
    Thanks alot now it works for me !!!

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    98
    why am i getting this error?

    Compiling...
    ssszs.cpp
    C:\ssszs\ssszs.cpp(111) : error C2084: function 'int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)' already has a body
    Error executing cl.exe.

    ssszs.exe - 1 error(s), 0 warning(s)

  11. #11
    Registered User
    Join Date
    May 2002
    Posts
    27
    make sure its a win32 app.

  12. #12
    Registered User
    Join Date
    Feb 2002
    Posts
    98
    that is what im starting with, win 32 application, and its giving me that error

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21