Running OpenGL problem..Please Help me!

Running OpenGL problem..Please Help me!

Post by ah fat » Sun, 13 Feb 2000 04:00:00



hi,
    i am a beginner to OpenGL programming. i have wrote a simple OpenGL
program(actually taken from book).i have compiled it and run. i felt happy
when i finally wrote a first OpenGL program.The next day, i run the program
again, my system(windows) hang. i need to press crtl-alt-delete to restart
my computer.Why?Only a day, my program can't run anymore!Why? it's sad for a
beginner who like OpenGL programming very much.(i use RIVA TNT 2 graphics
card and windows 98 with Directx 7. i use Visual C++ 6.0).i can't continue
with my study without solve this problem.Can u please help me?Please.....

Below is my program code:(i already add opengl32.lib, glu32.lib and
glaux.lib.i
not think that my code has problem but i hardly find the problem occur.)
/*A simple OpenGL program using a C interface designed to be a quick
introduction
  into the minimal settings needed to run OpenGL under Microsoft Windows.
  (Does not hold onto the DC/RC)
*/

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

LONG WINAPI WindowProc(HWND, UINT, WPARAM, LPARAM);
void DrawOpenGLScene(void);
HGLRC SetUpOpenGL(HWND hWnd);

char szAppName[] = "OpenGL";
char szTitle[] = "A Simple OpenGL Program";

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs,
int nCmdShow)
{
 HWND hWnd;
 WNDCLASSEX wcl;
 MSG msg;

 wcl.cbSize = sizeof(WNDCLASSEX);
 wcl.style = CS_HREDRAW | CS_VREDRAW;
 wcl.lpfnWndProc = WindowProc;
 wcl.cbClsExtra = 0;
 wcl.cbWndExtra = 0;
 wcl.hInstance = hThisInst;
 wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
 wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
 wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
 wcl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
 wcl.lpszClassName = szAppName;
 wcl.lpszMenuName = NULL;

 if(!RegisterClassEx(&wcl))
  return FALSE;

 hWnd = CreateWindow(
    szAppName,
    szTitle,
    WS_OVERLAPPEDWINDOW |
    WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
    CW_USEDEFAULT,
    0,
    CW_USEDEFAULT,
    0,
    NULL,
    NULL,
    hThisInst,
    NULL
     );
 if(!hWnd)
  return FALSE;

 ShowWindow(hWnd, nCmdShow);
 UpdateWindow(hWnd);

 while(GetMessage(&msg, NULL, 0, 0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }

 return msg.wParam;

Quote:}

LONG WINAPI WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
 HDC hDC;
 static HGLRC hRC;
 PAINTSTRUCT ps;
 GLdouble gldAspect;
 GLsizei glnWidth, glnHeight;

 switch(message)
 {
  case WM_CREATE :
                hRC = SetUpOpenGL(hWnd);
                return 0;

  case WM_SIZE :

        hDC = GetDC(hWnd);
        wglMakeCurrent(hDC, hRC);

        glnWidth = (GLsizei)LOWORD(lParam);
        glnHeight = (GLsizei)HIWORD(lParam);
        gldAspect = (GLdouble)glnWidth/(GLdouble)glnHeight;

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        gluPerspective(
         30.0,
         gldAspect,
         1.0,
         10.0);
        glViewport(0, 0, glnWidth, glnHeight);

        wglMakeCurrent(NULL, NULL);
        ReleaseDC(hWnd, hDC);

        return 0;

  case WM_PAINT :

      hDC = BeginPaint(hWnd, &ps);
      wglMakeCurrent(hDC, hRC);

      DrawOpenGLScene();

      wglMakeCurrent(NULL, NULL);

      EndPaint(hWnd, &ps);

      return 0;

  case WM_DESTROY :
        wglDeleteContext(hRC);
        PostQuitMessage(0);

        return 0;

  default : return DefWindowProc(hWnd, message, wParam, lParam);
 }

 return 0;

Quote:}

HGLRC SetUpOpenGL(HWND hWnd)
{
 static PIXELFORMATDESCRIPTOR pfd = {
  sizeof(PIXELFORMATDESCRIPTOR),
  1,
  PFD_DRAW_TO_WINDOW |                  PFD_SUPPORT_OPENGL,
  PFD_TYPE_RGBA,
  24,
  0,0,0,
  0,0,0,
  0,0,
  0,0,0,0,0,
  16,
  0,
  0,
  PFD_MAIN_PLANE,
  0,
  0,
  0,
  0,
 };

 int nMyPixelFormatID;
 HDC hDC;
 HGLRC hRC;

 hDC = GetDC(hWnd);
 nMyPixelFormatID = ChoosePixelFormat(hDC, &pfd);

 if(!nMyPixelFormatID)
  return FALSE;

 SetPixelFormat(hDC, nMyPixelFormatID, &pfd);

 hRC = wglCreateContext(hDC);

 ReleaseDC(hWnd, hDC);

 return hRC;

Quote:}

void DrawOpenGLScene(void)
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

 glTranslatef(0.0f, 0.0f, -5.0f);

 glBegin(GL_TRIANGLES);
  glColor3f(0.0f, 0.0f, 0.0f);
  glVertex3f(0.0f, 0.0f, 0.0f);
  glColor3f(0.0f, 1.0f, 0.0f);
  glVertex3f(-1.0f, -1.0f, 0.0f);
  glColor3f(1.0f, 0.0f, 0.0f);
  glVertex3f(0.0f, 1.0f, 0.0f);
 glEnd();

 glBegin(GL_TRIANGLES);
  glColor3f(0.0f, 0.0f, 0.0f);
  glVertex3f(0.0f, 0.0f, 0.0f);
  glColor3f(0.0f, 0.0f, 1.0f);
  glVertex3f(1.0f, -1.0f, 0.0f);
  glColor3f(0.0f, 1.0f, 0.0f);
  glVertex3f(-1.0f, -1.0f, 0.0f);
 glEnd();

 glBegin(GL_TRIANGLES);
  glColor3f(0.0f, 0.0f, 0.0f);
  glVertex3f(0.0f, 0.0f, 0.0f);
  glColor3f(1.0f, 0.0f, 0.0f);
  glVertex3f(0.0f, 1.0f, 0.0f);
  glColor3f(0.0f, 0.0f, 1.0f);
  glVertex3f(1.0f, -1.0f, 0.0f);
 glEnd();

  glFlush();

Quote:}

from Edward Siow

 
 
 

1. Best system for running OpenGL (please help)

Hi there,

        I'm looking to get a new computer some time soon and can't decide what
system I should get.  At present, I am tossing up between getting a workstation
with 3D graphics accelerator cards and an Intel 450MHz CPU or getting a laptop
computer with a 300MHz CPU (again, Intel) and a 14.1" TFT screen.

        Does anyone out there know what OpenGL performance is like on such a
laptop?  I'm keen on the laptop but my priority is to get a computer with solid
OGL graphics performance as my old computer keeps letting me down in that
department.  I'd appreciate any comments on the two systems above but please
don't suggest other machines (eg. SGI) as I need an Intel computer.  Aside from
the differences I've highlighted, I'd be aiming to get the same on both systems
(ie same RAM, OS etc).

Many thanks,
TBS
--
aka:  The Bad Seed                                Au Claire De La Luunaaarghh!!

"You have to have a superiority complex to work in this business."
                                                  -- Sam Newman, The Footy Show.

2. Animated .gif

3. Problems Running 3D Studio - PLEASE HELP!

4. Dust & Smoke ... JOBS (UK) Millfilm

5. Please Help Me! OpenGL problem

6. How can I remove part of a character?

7. OpenGL Problem- - Please Help

8. Character Studio -VS- Bones Pro MAX

9. Please help with opengl/glide problem

10. Problems compiling with MS Vis C++ using openGL and GLUT, please help

11. problems with openGL and quake II, please help

12. Please Help: problem with OpenGL offscreen rendering

13. OpenGL Problem - Please Help