Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-29-2005, 07:50 AM   #1 (permalink)
Monkeymatt
<?php echo 'PHP Guru';?>
 
Join Date: Jun 2005
Posts: 2
Monkeymatt is on a distinguished road
C++ OpenGl problem

I am trying to make a simple OpenGl program, and it's not working. The thing that's making me mad is that it is straight from a book. It's giving me this error message:

Quote:
The procedure entry point ChoosePixelFormat could not be located in the dynamic link library OpenGl32.DLL
Here's the code:

Code:
#define WIN32_LEAN_AND_MEAN
#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="My Class";
    windowClass.hIconSm=LoadIcon(NULL, IDI_WINLOGO);
    
    if (!RegisterClassEx(&windowClass)) {
        return 0;
    }
    
    hwnd=CreateWindowEx(NULL,
        "My Class",
        "The OpenGL Window Application",
        WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
        100, 100,
        400, 400,
        NULL,
        NULL,
        hInstance,
        NULL);
    
    if (!hwnd) {
        return 0;
    }
    
    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;
}
Monkeymatt is offline   Reply With Quote
Old 06-29-2005, 10:40 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
I've moved the thread here, since it is more appropriate in this section

According to this instruction you need to perform a few logistics, befor your program will work, like linking with a few libraries.
Since you didn't provide any info on what compiler/IDE you're using, I have no idear if the described steps here are, what you've missed out on, or if you'øve allready covered that.
I'm guessing you're using this tutorial for your programming, since I see parts of your code as their examples.
But since you're not providing any otehr information, than the error, I'm stumped at teh moment, a compiler/IDE and the steps you've used up untill now, will provide a better angle from my perspective on this.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 06-29-2005, 11:31 AM   #3 (permalink)
Monkeymatt
<?php echo 'PHP Guru';?>
 
Join Date: Jun 2005
Posts: 2
Monkeymatt is on a distinguished road
I'm using Dev C++ compiler. I have it linked with the OpenGL32.lib, GLU32.lib and GLAUX.lib
Monkeymatt is offline   Reply With Quote
Old 07-03-2005, 10:19 AM   #4 (permalink)
fp_unit
mike
 
Join Date: Jan 2005
Location: Ottawa, ON
Posts: 79
fp_unit is on a distinguished road
I managed to get it working pretty easily in Visual Studio .NET 2003 (your code you listed). I didnt change one thing and it compiled my first try, here's how I did it:

* File->New Project->Visual C++ Application->Win32 Application [ gave project a name ]
* File->Add New Item->C++ Source File [ named "main.cpp" ]
* Pasted Code
* Project->$(Project Name) Properties->Linker->Input->Additional Dependencies->opengl32.lib glu32.lib
* Build->Build Project
* Debug->Start without Debugging

Worked perfectly, no compile errors. I took a screenshot but I have no way to upload it, in case your wondering its a small red triangle on a black background, pretty simple OpenGL stuff.

EDIT: Screenshot, enjoy
http://munro.humber.ca/~dwnm0041/opengl-app.JPG

Try again in Dev-C++, create a new project (C++), Windows Application (not console), add new file (c++), copy/paste code into file, save, set linker options (you should only need opengl32.lib and glu32.lib) then compile. I would guess that somewhere along the lines of setting up your project you chose "C application" or "Console Application" or something like that. Keep trying, OpenGL is fun
fp_unit is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kaat a talking bot in c nvictor Platform/API C++ 10 05-19-2005 01:16 PM
c simple question problem with switch case if13121 Standard C, C++ 1 10-24-2004 09:43 PM
C problem saurabh1905 Standard C, C++ 2 06-11-2004 01:00 AM
edit? anon Lounge 10 11-21-2002 03:02 PM


All times are GMT -8. The time now is 11:26 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting