🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

OO Nehe

Started by
6 comments, last by chewy 23 years, 11 months ago
has anyone created an opengl class to encapsulate the windows application from nehe. I''m trying to and I''m having problems and would like to know how other people are doing it. here''s my class that I have so far.
    
class TGlApp
{
private:
  HDC hDC;
  HGLRC	hRC;
  HWND hWnd;
  HINSTANCE	hInstance;

protected:
  int InitGL();
  void KillGLWindow();
  LRESULT CALLBACK WndProc(HWND	hWnd,UINT uMsg,	WPARAM wParam,LPARAM lParam);

public:
  bool fullscreen;
  int width, height;
  char* title;
  int bits;
  __fastcall TGlApp();
  void ReSizeGLScene(int width, int height);
  int DrawGLScene();
  bool CreateGLWindow();
  __fastcall ~TGlApp();
};

    
my problem is (which some may be able to see) is with the WndProc. Anyone interested in helping?
Advertisement
Maybe you should try something like this:

    class TGlApp{public:  TGlApp();  ~TGlApp();  bool       CreateGLWindow(const char* title, int width, int height, int bits, bool fullscreen);  void       KillGLWindow();  void       ReSizeGLScene(int width, int height);  int        DrawGLScene();protected:  int        InitGL();  HWND       m_hWnd;  HINSTANCE  m_hInstance;  HDC        m_hDC;  HGLRC      m_hRC;  bool       m_fullscreen;  int        m_width, m_height;  char*      m_title;  int        m_bits;private:  static     LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam,LPARAM lParam);};    

Hmm- I dunno.. I''m at work right now and can''t help.. Just wanted to say this is a topic I''m VERY interested in pursuing.. I''ve thought about doing this myself..

But if you notice in some news A LONG time ago, NeHe alluded to some revision of the base code that may be more OO... Email him and DEMAND it.. hehe.. I''ve asked but he''s trying to work it into a tutorial..

GIVE ME THE CODE NEHE!!


bosco()

I''m glad others are interested in this.

I can see I need to give more information about what my problem is at this point.

on the create of the object I''m doing this
    _fastcall TGlApp :: TGlApp(){  fullscreen = false;  GLuint PixelFormat; // Holds The ResultsA fter Searching For A Match  WNDCLASS	wc;					  // Windows Class Structure  DWORD		dwExStyle;	// Window Extended Style  DWORD		dwStyle;	// Window Style  RECT		WindowRect;	// Grabs Rectangle Upper Left / Lower Right Values  WindowRect.left=(long)0;	// Set Left Value To 0  WindowRect.right=(long)width; // Set Right Value To Requested Width  WindowRect.top=(long)0;	// Set Top Value To 0  WindowRect.bottom=(long)height;	// Set Bottom Value To Requested Height hInstance = GetModuleHandle(NULL);  // Grab An Instance For Our Window wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window. wc.lpfnWndProc	= (WNDPROC) WndProc; // WndProc Handles Messages...    


It''s the last line that is giving me problems. the compilier says "Member function must be called or its address taken"

Maybe I need to move this to somewhere else?


I''m definately thinking that your WndProc should be a static member variable.

-Mezz
I am doing exactly this in my engine. I created a simple framework, it works very well. Here''s the deal.

You create a main.cpp. In this file you hold WndProc, and WinMain, and stick the game loop there, and windows initialization code. No OGL there. In the game loop, you stick a call to some custom defined callback function. You never touch this code again, and reuse it from project to project. Create an opengl wrapper, and just instantiate it from this callback function.
Mezz, you are exactly right! I missed the static part in the previous post. This did fix the problem. I''ve had that problem before and I miss it every time. Thanks!

Kill, I''d be very interested in seeing some of your code. I''m trying to hold true to the nehe tutorials right now but I know that I will eventually do something like you are doing in the near future.

Thanks to everyone for the responses. I''m sure I''ll have more questions as I finish re-going through all these lessons.
ok kill the more I think about it the more I want to do it your way but how do you manage things like resizing and key strokes if the wndproc is out side of the gl Class?

This topic is closed to new replies.

Advertisement