Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Starting OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 huymoi7   Members   -  Reputation: 122

Like
1Likes
Like

Posted 11 March 2013 - 11:39 PM

Hi I'm starting out learning OpenGL from the book "Beginning OpenGL Game programming".

 

I am using Code blocks as an IDE and Windows 7 as an operating system. I've followed the steps in this tutorial to setup Code blocks mingw with GLUT.

 

http://www.deannicholls.co.uk/tutorials/show/cpp_glut

 

When I take the source code from chapter 2 on the CD and I copy and paste it into my IDE I get the attached print screen as an error. 

 

The print screen indicates that the SetPixelFormat() method cannot be referenced. I did some research and it appears that the SetPixelFormat() method is under the WGL reference

 

http://msdn.microsoft.com/en-us/library/windows/desktop/dd369049(v=vs.85).aspx

 

and I infer that GLUT installs WGL for me. So why can't I reference SetPixelFormat()? What am I missing? Do I have to do some kind of linking first?

 

Note - I was able to successfully copy, paste, build and run the source code of chapter 1 without any problems.

Attached Thumbnails

  • help.png

Edited by huymoi7, 11 March 2013 - 11:44 PM.


Sponsor:

#2 huymoi7   Members   -  Reputation: 122

Like
0Likes
Like

Posted 11 March 2013 - 11:55 PM

Attached is a copy of the source code from chapter 2.

Attached Files



#3 beans222   Members   -  Reputation: 1136

Like
1Likes
Like

Posted 12 March 2013 - 12:11 AM

Check that gdi32.lib is being linked.


New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

 


#4 Aldacron   GDNet+   -  Reputation: 3240

Like
1Likes
Like

Posted 12 March 2013 - 12:32 AM

SetPixelFormat is not part of WGL, it is part of the gdi32 DLL. The WGL* stuff is in the opengl32 DLL. Glut doesn't install any of that for you, but it is all available as part of your compiler installation.

Your problem is that you are calling Win32 API functions (ChoosePixelFormat, SetPixelFormat and so on) without linking to the Win32 API libraries. Furthermore, if you are using glut you don't need to be making all of those calls in the first place. Glut exists to hide that from you so that you can more easily get up and running with cross platform OpenGL. You should be creating an OpenGL context and window through the Glut API, *not* win32. So you need to make up your mind which way you're going to go. If you want to use Win32, then link to the appropriate Win32 libraries (kernel32.lib, gdi32.lib and so one) and ditch glut. Otherwise, take out all the win32 stuff and learn how to use glut.



#5 huymoi7   Members   -  Reputation: 122

Like
0Likes
Like

Posted 12 March 2013 - 12:35 AM

Perfect, I never would have worked that out thanks!



#6 huymoi7   Members   -  Reputation: 122

Like
0Likes
Like

Posted 12 March 2013 - 12:39 AM

SetPixelFormat is not part of WGL, it is part of the gdi32 DLL. The WGL* stuff is in the opengl32 DLL. Glut doesn't install any of that for you, but it is all available as part of your compiler installation.

Your problem is that you are calling Win32 API functions (ChoosePixelFormat, SetPixelFormat and so on) without linking to the Win32 API libraries. Furthermore, if you are using glut you don't need to be making all of those calls in the first place. Glut exists to hide that from you so that you can more easily get up and running with cross platform OpenGL. You should be creating an OpenGL context and window through the Glut API, *not* win32. So you need to make up your mind which way you're going to go. If you want to use Win32, then link to the appropriate Win32 libraries (kernel32.lib, gdi32.lib and so one) and ditch glut. Otherwise, take out all the win32 stuff and learn how to use glut.

 

Thanks for clearing that up for me. I'm just following this book right now. I don't know much about the difference between the Win32 and GLUT APIs, but if using both is redundant than you're right I should just use one. I'll also keep this in mind while I go through the book.



#7 Aldacron   GDNet+   -  Reputation: 3240

Like
1Likes
Like

Posted 12 March 2013 - 07:46 AM

I don't know much about the difference between the Win32 and GLUT APIs, but if using both is redundant than you're right I should just use one.

 

Every operating system has a collection of libraries that you can use to interface with the hardware. On Windows, the classic API is called Win32. When you use GLUT on Windows, it is using the Win32 APIs under the hood to get an OpenGL context up and running. Instead of you calling SetPixelFormat and friends directly, GLUT does it for you when you ask it to create a window. GLUT also wraps up other stuff for you into a common interface, such as keyboard and mouse input. Then, if you want to move your app to Linux or Mac, where the operating system APIs are very different from Win32, you can just keep using GLUT without any changes. Otherwise, you'd have to rewrite all of the window creation and input handling code for each operating system.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS