Results 1 to 3 of 3

Thread: can someone get this to work

  1. #1
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    6

    can someone get this to work

    i cant get this to work in my compiler, if you can get it to work tell me which compiler you used to do it:

    // 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
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: can someone get this to work

    Hi !

    I havn't tried it, but could you be a bit more specific about what your problem is ?
    do you get some error messages or what, and that case what are they ?

    Mikael

  3. #3

    Re: can someone get this to work

    try setting the current matrix to GL_MODELVIEW also when you get the WM_CREATE message...hope this works!

Similar Threads

  1. Replies: 5
    Last Post: 04-03-2015, 04:34 AM
  2. Work Group and Work Item sizes
    By howard in forum OpenCL
    Replies: 1
    Last Post: 03-08-2013, 11:08 PM
  3. Replies: 2
    Last Post: 12-14-2011, 05:47 PM
  4. Replies: 1
    Last Post: 11-18-2011, 10:05 AM
  5. help with work items in work groups
    By gatodelsol in forum OpenCL
    Replies: 3
    Last Post: 09-14-2011, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean