• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By tj8146
      I am using immediate mode for OpenGL and I am creating a 2D top down car game. I am trying to configure my game loop in order to get my car-like physics working on a square shape. I have working code but it is not doing as I want it to. I am not sure as to whether it is my game loop that is incorrect or my code for the square is incorrect, or maybe both! Could someone help because I have been trying to work this out for over a day now
      I have attached my .cpp file if you wish to run it for yourself.. 
      WinMain code:
      /******************* WIN32 FUNCTIONS ***************************/ int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure bool done=false; // Bool Variable To Exit Loop Car car; car.x = 220; car.y = 140; car.dx = 0; car.dy = 0; car.ang = 0; AllocConsole(); FILE *stream; freopen_s(&stream, "CONOUT$", "w", stdout); // Create Our OpenGL Window if (!CreateGLWindow("OpenGL Win32 Example",screenWidth,screenHeight)) { return 0; // Quit If Window Was Not Created } while(!done) // Loop That Runs While done=FALSE { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=true; // If So done=TRUE break; } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { if(keys[VK_ESCAPE]) done = true; void processKeys(Car& car); //process keyboard while (game_is_running) { loops = 0; while (GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) { update(car); // update variables next_game_tick += SKIP_TICKS; loops++; } display(car); // Draw The Scene SwapBuffers(hDC); // Swap Buffers (Double Buffering) } } } // Shutdown KillGLWindow(); // Kill The Window return (int)(msg.wParam); // Exit The Program } //WIN32 Processes function - useful for responding to user inputs or other events. LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam) // Additional Message Information { switch (uMsg) // Check For Windows Messages { case WM_CLOSE: // Did We Receive A Close Message? { PostQuitMessage(0); // Send A Quit Message return 0; // Jump Back } break; case WM_SIZE: // Resize The OpenGL Window { reshape(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height return 0; // Jump Back } break; case WM_LBUTTONDOWN: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); LeftPressed = true; } break; case WM_LBUTTONUP: { LeftPressed = false; } break; case WM_MOUSEMOVE: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); } break; case WM_KEYDOWN: // Is A Key Being Held Down? { keys[wParam] = true; // If So, Mark It As TRUE return 0; // Jump Back } break; case WM_KEYUP: // Has A Key Been Released? { keys[wParam] = false; // If So, Mark It As FALSE return 0; // Jump Back } break; } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hWnd,uMsg,wParam,lParam); }  
      C++ and OpenGL code:
      int mouse_x=0, mouse_y=0; bool LeftPressed = false; int screenWidth=1080, screenHeight=960; bool keys[256]; float radiansFromDegrees(float deg) { return deg * (M_PI / 180.0f); } float degreesFromRadians(float rad) { return rad / (M_PI / 180.0f); } bool game_is_running = true; const int TICKS_PER_SECOND = 50; const int SKIP_TICKS = 1000 / TICKS_PER_SECOND; const int MAX_FRAMESKIP = 10; DWORD next_game_tick = GetTickCount(); int loops; typedef struct { float x, y; float dx, dy; float ang; }Car; //OPENGL FUNCTION PROTOTYPES void display(const Car& car); //called in winmain to draw everything to the screen void reshape(int width, int height); //called when the window is resized void init(); //called in winmain when the program starts. void processKeys(Car& car); //called in winmain to process keyboard input void update(Car& car); //called in winmain to update variables /************* START OF OPENGL FUNCTIONS ****************/ void display(const Car& car) { const float w = 50.0f; const float h = 50.0f; glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(100, 100, 0); glBegin(GL_POLYGON); glVertex2f(car.x, car.y); glVertex2f(car.x + w, car.y); glVertex2f(car.x + w, car.y + h); glVertex2f(car.x, car.y + h); glEnd(); glFlush(); } void reshape(int width, int height) // Resize the OpenGL window { screenWidth = width; screenHeight = height; // to ensure the mouse coordinates match // we will use these values to set the coordinate system glViewport(0, 0, width, height); // Reset the current viewport glMatrixMode(GL_PROJECTION); // select the projection matrix stack glLoadIdentity(); // reset the top of the projection matrix to an identity matrix gluOrtho2D(0, screenWidth, 0, screenHeight); // set the coordinate system for the window glMatrixMode(GL_MODELVIEW); // Select the modelview matrix stack glLoadIdentity(); // Reset the top of the modelview matrix to an identity matrix } void init() { glClearColor(1.0, 1.0, 0.0, 0.0); //sets the clear colour to yellow //glClear(GL_COLOR_BUFFER_BIT) in the display function //will clear the buffer to this colour. } void processKeys(Car& car) { if (keys[VK_UP]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += cdx; car.dy += cdy; } if (keys[VK_DOWN]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += -cdx; car.dy += -cdy; } if (keys[VK_LEFT]) { car.ang -= 2; } if (keys[VK_RIGHT]) { car.ang += 2; } } void update(Car& car) { car.x += car.dx*next_game_tick; }  
      game.cpp
    • By tj8146
      I am using immediate mode for OpenGL and I am creating a 2D top down car game. I am trying to configure my game loop in order to get my car-like physics working on a square shape. I have working code but it is not doing as I want it to. I am not sure as to whether it is my game loop that is incorrect or my code for the square is incorrect, or maybe both! Could someone help because I have been trying to work this out for over a day now
      I have attached my .cpp file if you wish to run it for yourself.. 
       
      This is my C++ and OpenGL code:
      int mouse_x=0, mouse_y=0; bool LeftPressed = false; int screenWidth=1080, screenHeight=960; bool keys[256]; float radiansFromDegrees(float deg) { return deg * (M_PI / 180.0f); } float degreesFromRadians(float rad) { return rad / (M_PI / 180.0f); } bool game_is_running = true; const int TICKS_PER_SECOND = 50; const int SKIP_TICKS = 1000 / TICKS_PER_SECOND; const int MAX_FRAMESKIP = 10; DWORD next_game_tick = GetTickCount(); int loops; typedef struct { float x, y; float dx, dy; float ang; }Car; //OPENGL FUNCTION PROTOTYPES void display(const Car& car); //called in winmain to draw everything to the screen void reshape(int width, int height); //called when the window is resized void init(); //called in winmain when the program starts. void processKeys(Car& car); //called in winmain to process keyboard input void update(Car& car); //called in winmain to update variables /************* START OF OPENGL FUNCTIONS ****************/ void display(const Car& car) { const float w = 50.0f; const float h = 50.0f; glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(100, 100, 0); glBegin(GL_POLYGON); glVertex2f(car.x, car.y); glVertex2f(car.x + w, car.y); glVertex2f(car.x + w, car.y + h); glVertex2f(car.x, car.y + h); glEnd(); glFlush(); } void reshape(int width, int height) // Resize the OpenGL window { screenWidth = width; screenHeight = height; // to ensure the mouse coordinates match // we will use these values to set the coordinate system glViewport(0, 0, width, height); // Reset the current viewport glMatrixMode(GL_PROJECTION); // select the projection matrix stack glLoadIdentity(); // reset the top of the projection matrix to an identity matrix gluOrtho2D(0, screenWidth, 0, screenHeight); // set the coordinate system for the window glMatrixMode(GL_MODELVIEW); // Select the modelview matrix stack glLoadIdentity(); // Reset the top of the modelview matrix to an identity matrix } void init() { glClearColor(1.0, 1.0, 0.0, 0.0); //sets the clear colour to yellow //glClear(GL_COLOR_BUFFER_BIT) in the display function //will clear the buffer to this colour. } void processKeys(Car& car) { if (keys[VK_UP]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += cdx; car.dy += cdy; } if (keys[VK_DOWN]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += -cdx; car.dy += -cdy; } if (keys[VK_LEFT]) { car.ang -= 2; } if (keys[VK_RIGHT]) { car.ang += 2; } } void update(Car& car) { car.x += car.dx*next_game_tick; } My WinMain code:
      /******************* WIN32 FUNCTIONS ***************************/ int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure bool done=false; // Bool Variable To Exit Loop Car car; car.x = 220; car.y = 140; car.dx = 0; car.dy = 0; car.ang = 0; AllocConsole(); FILE *stream; freopen_s(&stream, "CONOUT$", "w", stdout); // Create Our OpenGL Window if (!CreateGLWindow("OpenGL Win32 Example",screenWidth,screenHeight)) { return 0; // Quit If Window Was Not Created } while(!done) // Loop That Runs While done=FALSE { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=true; // If So done=TRUE break; } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { if(keys[VK_ESCAPE]) done = true; void processKeys(Car& car); //process keyboard while (game_is_running) { loops = 0; while (GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) { update(car); // update variables next_game_tick += SKIP_TICKS; loops++; } display(car); // Draw The Scene SwapBuffers(hDC); // Swap Buffers (Double Buffering) } } } // Shutdown KillGLWindow(); // Kill The Window return (int)(msg.wParam); // Exit The Program } //WIN32 Processes function - useful for responding to user inputs or other events. LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam) // Additional Message Information { switch (uMsg) // Check For Windows Messages { case WM_CLOSE: // Did We Receive A Close Message? { PostQuitMessage(0); // Send A Quit Message return 0; // Jump Back } break; case WM_SIZE: // Resize The OpenGL Window { reshape(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height return 0; // Jump Back } break; case WM_LBUTTONDOWN: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); LeftPressed = true; } break; case WM_LBUTTONUP: { LeftPressed = false; } break; case WM_MOUSEMOVE: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); } break; case WM_KEYDOWN: // Is A Key Being Held Down? { keys[wParam] = true; // If So, Mark It As TRUE return 0; // Jump Back } break; case WM_KEYUP: // Has A Key Been Released? { keys[wParam] = false; // If So, Mark It As FALSE return 0; // Jump Back } break; } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hWnd,uMsg,wParam,lParam); }  
      game.cpp
    • By lxjk
      Hi guys,
      There are many ways to do light culling in tile-based shading. I've been playing with this idea for a while, and just want to throw it out there.
      Because tile frustums are general small compared to light radius, I tried using cone test to reduce false positives introduced by commonly used sphere-frustum test.
      On top of that, I use distance to camera rather than depth for near/far test (aka. sliced by spheres).
      This method can be naturally extended to clustered light culling as well.
      The following image shows the general ideas

       
      Performance-wise I get around 15% improvement over sphere-frustum test. You can also see how a single light performs as the following: from left to right (1) standard rendering of a point light; then tiles passed the test of (2) sphere-frustum test; (3) cone test; (4) spherical-sliced cone test
       

       
      I put the details in my blog post (https://lxjk.github.io/2018/03/25/Improve-Tile-based-Light-Culling-with-Spherical-sliced-Cone.html), GLSL source code included!
       
      Eric
    • By Fadey Duh
      Good evening everyone!

      I was wondering if there is something equivalent of  GL_NV_blend_equation_advanced for AMD?
      Basically I'm trying to find more compatible version of it.

      Thank you!
    • By Jens Eckervogt
      Hello guys, 
       
      Please tell me! 
      How do I know? Why does wavefront not show for me?
      I already checked I have non errors yet.
      using OpenTK; using System.Collections.Generic; using System.IO; using System.Text; namespace Tutorial_08.net.sourceskyboxer { public class WaveFrontLoader { private static List<Vector3> inPositions; private static List<Vector2> inTexcoords; private static List<Vector3> inNormals; private static List<float> positions; private static List<float> texcoords; private static List<int> indices; public static RawModel LoadObjModel(string filename, Loader loader) { inPositions = new List<Vector3>(); inTexcoords = new List<Vector2>(); inNormals = new List<Vector3>(); positions = new List<float>(); texcoords = new List<float>(); indices = new List<int>(); int nextIdx = 0; using (var reader = new StreamReader(File.Open("Contents/" + filename + ".obj", FileMode.Open), Encoding.UTF8)) { string line = reader.ReadLine(); int i = reader.Read(); while (true) { string[] currentLine = line.Split(); if (currentLine[0] == "v") { Vector3 pos = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3])); inPositions.Add(pos); if (currentLine[1] == "t") { Vector2 tex = new Vector2(float.Parse(currentLine[1]), float.Parse(currentLine[2])); inTexcoords.Add(tex); } if (currentLine[1] == "n") { Vector3 nom = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3])); inNormals.Add(nom); } } if (currentLine[0] == "f") { Vector3 pos = inPositions[0]; positions.Add(pos.X); positions.Add(pos.Y); positions.Add(pos.Z); Vector2 tc = inTexcoords[0]; texcoords.Add(tc.X); texcoords.Add(tc.Y); indices.Add(nextIdx); ++nextIdx; } reader.Close(); return loader.loadToVAO(positions.ToArray(), texcoords.ToArray(), indices.ToArray()); } } } } } And It have tried other method but it can't show for me.  I am mad now. Because any OpenTK developers won't help me.
      Please help me how do I fix.

      And my download (mega.nz) should it is original but I tried no success...
      - Add blend source and png file here I have tried tried,.....  
       
      PS: Why is our community not active? I wait very longer. Stop to lie me!
      Thanks !
  • Advertisement
  • Advertisement
Sign in to follow this  

OpenGL OpenGL hangs in Visual C++ Express

This topic is 3735 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

When I try and run an OpenGL app in C++ Express it hangs most of the time. What's up with that? [EDIT]I've added more code
//---------------------------------------------------------------------------

#include "File1.h"
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>

#pragma hdrstop

//---------------------------------------------------------------------------
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL				InitInstance(HINSTANCE, int);

HINSTANCE hInst;
char szTitle[10] = "test";					// The title bar text
char  szWindowClass[10] = "test1";

const unsigned short SCREEN_WIDTH = 800, SCREEN_HEIGHT = 600;
BYTE SCREEN_COLORBITS = 32, SCREEN_DEPTH = 16;
COGL ogl;
#pragma argsused
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MSG msg;

	WNDCLASSEX wndclassex = {0};

	// Fill the fields we care about
	wndclassex.cbSize = sizeof(WNDCLASSEX);
	wndclassex.style = CS_HREDRAW | CS_VREDRAW;
	wndclassex.lpfnWndProc = WndProc;
	wndclassex.hInstance = hInstance;
	wndclassex.lpszClassName = szWindowClass;
	wndclassex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	//wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_CROSS), IMAGE_CURSOR, 0, 0, LR_SHARED);
    //wndclassex.hCursor = (HCURSOR)LoadImage(NULL, "images/Cursor1.cur", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
    wndclassex.hCursor = LoadCursor(NULL, IDC_ARROW);

	RegisterClassEx(&wndclassex);

	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	GLuint texture_id;
	glGenTextures(1, &texture_id);

	// Bind the texture to the texture arrays index and init the texture
	glBindTexture(GL_TEXTURE_2D, texture_id);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	GLint internal_format = GL_RGB8;    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	const unsigned int image_width = 512;
	const unsigned int image_height = 512;
	const unsigned int cui_tmp = image_width*image_height*3; 
	GLubyte *image_data_tmp = new GLubyte[cui_tmp];
	for(int i=0; i<cui_tmp; ++i)
		image_data_tmp = 0;

	glTexImage2D(GL_TEXTURE_2D, 0, internal_format, image_width,
            image_height, 0, GL_RGB, GL_UNSIGNED_BYTE,
            image_data_tmp);	

     delete[] image_data_tmp;

	while(!GetAsyncKeyState(VK_ESCAPE))
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}//end if		
        else
		{
				//ref_playingobj.ogg_mmplayer.playMM(b_endofplayback, ref_playingobj.quad_coords);	
				//ogl.MainLoop(playmediafile);	

				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);				
				glLoadIdentity();		
				glBindTexture(GL_TEXTURE_2D, texture_id);	

				glColor4f(1.0f, 1.0f, 1.0f, 1.0f);		
				glBegin(GL_QUADS);

				glTexCoord2f(0.0, 0.0); glVertex2s(0, 0);
				glTexCoord2f(0.0, 0.9375f); glVertex2s(0, 600);
				glTexCoord2f(0.6875f, 0.9375f); glVertex2s(800, 600);
				glTexCoord2f(0.6875f, 0.0); glVertex2s(800, 0);
				glEnd();

				glFlush();
				SwapBuffers(ogl.hdc);
         }//end else		
	} // end of while


	ReleaseDC(ogl.hwnd, ogl.hdc); // Be sure to free up the window's HDC
    wglMakeCurrent(NULL, NULL); // Set render context back
    wglDeleteContext(ogl.hglrc); // Delete render context
    ogl.hglrc = NULL;
	ogl.hdc = NULL;
	UnregisterClass(szWindowClass, hInstance); // Free up the WNDCLASSEX

	return 0;
}
//---------------------------------------------------------------------------
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   RECT rect = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT }; // Desired window client rect

	DWORD winStyleEx = WS_EX_APPWINDOW;
    DWORD winStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
	//DWORD winStyle = WS_CAPTION | WS_SYSMENU; // Window style
        //DWORD winStyle = WS_MAXIMIZE;

	// Adjust window rect so it gives us our desired client rect when we
	AdjustWindowRectEx(&rect, winStyle, false, winStyleEx);
   
   hWnd = /*CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);*/
	  CreateWindowEx(winStyleEx,
                                szWindowClass,
                                szTitle,
                                winStyle,
                                0,
                                0,
                                rect.right - rect.left,
                                rect.bottom - rect.top,
                                NULL,
                                NULL,
                                hInstance,
                                NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ogl.hwnd = hWnd;
   ogl.hdc = GetDC(hWnd);

   //ChangeToFullScreen();
   if(!ogl.initOGL((BYTE)SCREEN_COLORBITS, (BYTE)SCREEN_DEPTH))
   {
		UnregisterClass(szWindowClass, hInstance); // Free up the WNDCLASSEX
	   	return EXIT_FAILURE; // Something bad happened
   }//end if

   ogl.setupOGL();

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

   return TRUE;
}
//------------------------------------------------------------------------------------
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
//------------------------------------------------------------------------------------
// Message handler for about box.

//------------------------------------------------------------------------------------
bool COGL::initOGL(const BYTE &colorBits,
				   const BYTE &depthBits)
{
        // Set the pixel format
	if(!setPixelFormat(colorBits, depthBits))
		return false;

	// Set the render context
	if(!setRenderContext())
		return false;

     return true;
}
//------------------------------------------------------------------------------------
bool COGL::setPixelFormat(const BYTE &colorBits, const BYTE &depthBits)
{
        // Declare a pixel format descriptor
        PIXELFORMATDESCRIPTOR pfd = {
	        sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
	        1,                     // version number
	        PFD_DRAW_TO_WINDOW |   // support window
	        PFD_SUPPORT_OPENGL |   // support OpenGL
	        PFD_DOUBLEBUFFER,      // double buffered
	        PFD_TYPE_RGBA,         // RGBA type
	        24,                    // 24-bit color depth
	        8, 0, 8, 0, 8, 0,      // color bits ignored
	        8,                     // no alpha buffer
	        0,                     // shift bit ignored
            0,                     // no accumulation buffer
	        0, 0, 0, 0,            // accum bits ignored
	        16,                    // 24-bit z-buffer
	        0,                     // no stencil buffer
	        0,                     // no auxiliary buffer
	        PFD_MAIN_PLANE,        // main layer
	        0,                     // reserved
	        0, 0, 0                // layer masks ignored
	        };	


	// Choose a compatible pixel format (storing the pixel format index in "result")
	int result = ChoosePixelFormat(hdc, &pfd);
        // Error Check
        if(result == 0)
                return false;

	// Attempt to set the pixel format
	if(!SetPixelFormat(hdc, result, &pfd))
		return false;

	return true; // Success
}
//------------------------------------------------------------------------------------
bool COGL::setRenderContext()
{
        // Create the OpenGL render context
	hglrc = wglCreateContext(hdc);

        // Error Check
        if(hglrc == NULL)
                return false;

	// Make it the current render context
	if(!wglMakeCurrent(hdc, hglrc))
	{
		DWORD ii = GetLastError();
		return false;
	}//end if

        //set view port
        glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glOrtho(0.0, (GLdouble) SCREEN_WIDTH, 0.0, (GLdouble) SCREEN_HEIGHT, -1.0, 1.0);
	//gluPerspective(60.0f,(GLfloat)SCREEN_WIDTH/(GLfloat)SCREEN_HEIGHT, CAMNEAR, CAMFAR);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	return true; // Success
}
//------------------------------------------------------------------------------------
void COGL::setupOGL()
{
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_CULL_FACE);        
        glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
        glClearDepth(1.0f);
        glFrontFace(GL_CW);
        glCullFace(GL_BACK);
        glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

        //glPixelStorei ( GL_UNPACK_ALIGNMENT, 4 );
        //glPixelStorei ( GL_PACK_ALIGNMENT, 4 );        

        //let mouse be in the middle of the window
        SetCursorPos(int(SCREEN_WIDTH  >> 1), int(SCREEN_HEIGHT  >> 1));        
}


[Edited by - miminawewe on January 30, 2008 6:03:48 AM]

Share this post


Link to post
Share on other sites
Advertisement
Yeah try pressing the 'pause' button when you're debugging to see where you are, and you can use the call stack view to see where your code has been.

Just a minor note here .. Using try / catch on OpenGL calls wont catch any errors because it's a C-style API. Try / catch are C++ style structured exception handling, the use of which in your main game loop may incur a serious performance penalty. Try to keep try / catch outside of your main loop.

Share this post


Link to post
Share on other sites
The loop runs a couple of times then it hangs. The hanging is irregular so breaking might not work.
The try / catch was for some c++ code which I have commented out. I thought it only slows down an application if an exception occurs but if none occurs then it's OK.

Share this post


Link to post
Share on other sites
Which is why you wait for it to hang before hitting pause to break into the app.

with regards to the exceptions, the issues is that when you enter a 'try' block the compiler has to do some setup in order to unwind the stack properly when an exception occurs; if you move the try block outside of the main loop this setup is only done once instead of every time.

That said, for one entry per-loop this may not be a problem (certainly unlikely to be a bottle neck with your current app) so I wouldn't worry too much about it right now, just keep it in mind for the future.

Share this post


Link to post
Share on other sites
The problem is also in borland turbo C++. I think the problem is the graphics adapter. It's an S3 prosavage/twister v1.1 2.40.103 It seems like if I set GL_CLAMP, Windows hangs, and if I don't set it or set GL_REPEAT it works.
Is there a place where I can see issues that various cards and adapters have? I think this will be a very important resource for anyone developing graphics applications especially OpenGL/DirectX.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement