Archived

This topic is now archived and is closed to further replies.

OO Nehe

This topic is 6363 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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);
};

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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()

Share this post


Link to post
Share on other sites
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?


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites