• 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 DirectInput equivelant

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

Hi, I'm sure you've seen this post before, but the search for me isn't turning up anything useful. I'm working on a D3D app, but for some reason I'm getting nervous about DirectX going away or being unsupported in future versions of windows, and contemplating the jump to OpenGL. Its been a long time since I used OpenGL, and I was wondering that since OpenGL would obviously take care of the graphics portion of my app, is there such a thing as an input library to replace DirectInput? I also understand that OpenAL can be used for sound, so I think I would be covered with that. My main concern is finding a free and easy-to-use input manager that gets direct access to keyboard and input device stuff. I'm not particularly interested with using SDL, for various reasons. Thanks for any/all replies. Cheers, roger_hq

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by roger_hq
is there such a thing as an input library to replace DirectInput?


Unless you want to use the Win32 input, there is not that I am aware of. I know SDL uses DirectDraw on Win32 platforms, but I do not think it uses DI as well. I've looked at the source before and came to that conclusion, but I may be off about the DI. When you go to linux and such, I am not sure what it uses really.

What I reccomend you do is use a OpenGL library that has input built in already. Take a look at GLFW. It has a great input system and is a very nice framework. I will be using that for our game. It's fairly easy to setup and use, but building it has a few quirks they don't really seem to mention. There are of course other libraries, such as GLUT and FreeGLUT, so that is what you would need to look into for a better input system.

As for OpenAL, good luck! I have been working with it for some time now, making my own audio library and it really is a pain. There's a lot to it that is not really explained and you have to figure out how everything works and what you can and can't do the hard way. Nevertheless, it's free and cross platform, so if you need some help with that feel free to PM me.

- Drew

Share this post


Link to post
Share on other sites
Drew,

I'm intrigued. One thing I'm trying to avoid is using something with a license that says I have to release all of my source code, give away my 1st born, etc. ad nauseum. I'm also very apprehensive about continuing with D3D, as I know microsoft just LOVES to stop supporting API's and with WGF coming out soon I fear that DirectX support will vanish. It looks like its pretty platform independent, which is of course good. I would like that too. So have you developed with it much? Do you know of any real-world games that have used it?

Thanks!

roger_hq

Share this post


Link to post
Share on other sites
Quote:
Original post by roger_hq
...for some reason I'm getting nervous about DirectX going away or being unsupported in future versions of windows...
Don't.

Quote:
...is there such a thing as an input library to replace DirectInput?
No. For Windows, just about nothing has as much low-level access to the hardware as the various DirectX components. Very few input device manufacturers go to the trouble of writing complex device drivers to expose functionality for real-time APIs. DirectInput implements a meta-driver, which the manufacturers write to (it's easier) and everyone lives happily ever after.

Of course, if all you're interested in is the keyboard and mouse, then you didn't really need DirectInput to begin with. The GDI GetKeyboardState API has high enough resolution for your most likely purposes, for example.

Share this post


Link to post
Share on other sites
Quote:
Original post by roger_hq
...microsoft just LOVES to stop supporting APIs
Actually, that's a very recent development, quite possibly in response to changes in developer behavior. For instance, VC6.0 was frequently blasted for its faulty implementation of the scope of for, but Microsoft took the right approach in maintaining the erroneous behavior as a default, with a switch to correct it, in order to support legacy code. VC7.x inverts that, requiring a switch to restore the incorrect scoping and compile legacy code without modification. There is also evidence of the Windows team having worked around the failings of third-party vendors, including IBM.

The architecture of DirectX and the decision to build it on top of COM was specifically chosen to provide backwards compatibility, and you can still find all the reference information for old interfaces in MSDN (with a warning message at the top of the page that the content has been archived, and may no longer be accurate). Doubtless, the same will be applied to 8.x and 9.x going forward. What more you want, I don't know.

Consequently, it seems that you are falling victim to hype and MS-bashing, causing you unnecessary apprehension and wasting your time. Your projects are suffering while you resolve this non-issue.

To each his own, I suppose.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry for the delay, started typing this and got distracted [lol]. Well to be honest, I have not use GLFW that much. However, I decided to give it a try because I saw a game they have been working on with it - Machinations. It just gave me a sense of awe of how awesome it was. I knew that this library definitly had to be worth while. Here's a simple sample application that I was working woth. All it does is draw a rotating triangle. It also displays the GL video info to the console window.


#include <windows.h>
#include <stdio.h> // For printf(), fopen() etc.
#include "glfw.h" // For GLFW, OpenGL and GLU

#pragma comment ( lib, "opengl32.lib" )
#pragma comment ( lib, "glu32.lib" )
#pragma comment ( lib, "GLFW.lib" )

void CalculateFrameRate();

void Init()
{
int width, height; // Window dimensions

// Get window size
glfwGetWindowSize( &width, &height );

// Make sure that height is non-zero to avoid division by zero
height = height < 1 ? 1 : height;

// Set viewport
glViewport( 0, 0, width, height );

// Clear color and depht buffers
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

// Set up projection matrix
glMatrixMode( GL_PROJECTION ); // Select projection matrix
glLoadIdentity(); // Start with an identity matrix
gluPerspective( // Set perspective view
65.0, // Field of view = 65 degrees
(double)width/(double)height, // Window aspect (assumes square pixels)
1.0, // Near Z clipping plane
100.0 // Far Z clippling plane
);

// Set up modelview matrix
glMatrixMode( GL_MODELVIEW ); // Select modelview matrix
glLoadIdentity(); // Start with an identity matrix
gluLookAt( // Set camera position and orientation
0.0, 0.0, 10.0, // Camera position (x,y,z)
0.0, 0.0, 0.0, // View point (x,y,z)
0.0, 1.0, 0.0 // Up-vector (x,y,z)
);

char* message = (char*)glGetString(GL_VENDOR);
char* message2 = (char*)glGetString(GL_RENDERER);
char* message3 = (char*)glGetString(GL_VERSION);
char* message4 = (char*)glGetString(GL_EXTENSIONS);

printf("Vendor: %s\nRenderer: %s\nVersion: %s\n Extensions: %s\n",message,message2,message3,message4);
}

void Draw( void )
{
if( glfwGetKey( GLFW_KEY_F1 ) )
{
}

if( glfwGetKey( GLFW_KEY_F2 ) )
{
}

if( glfwGetKey( GLFW_KEY_F3 ) )
{
}

if( glfwGetKey( GLFW_KEY_F4 ) )
{
}

if( glfwGetKey( GLFW_KEY_F5 ) )
{
}

double t = glfwGetTime(); // Time (in seconds)

// Clear color and depht buffers
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity(); // Start with an identity matrix

gluLookAt
( // Set camera position and orientation
0.0, 0.0, 10.0, // Camera position (x,y,z)
0.0, 0.0, 0.0, // View point (x,y,z)
0.0, 1.0, 0.0 // Up-vector (x,y,z)
);

glTranslatef( 0, 0, -5 );

// Rotate the triangle about the y-axis
glRotatef( 60.0f * (float)t, 0.0f, 1.0f, 0.0f );

// Let us draw a triangle, with color!
glBegin( GL_TRIANGLES ); // Tell OpenGL that we want to draw a triangle
glColor3f( 1.0f, 0.0f, 0.0f ); // Color for first corner (red)
glVertex3f( -5.0f, -4.0f, 0.0f ); // First corner of the triangle
glColor3f( 0.0f, 1.0f, 0.0f ); // Color for second corner (green)
glVertex3f( 5.0f, -4.0f, 0.0f ); // Second corner of the triangle
glColor3f( 0.0f, 0.0f, 1.0f ); // Color for third corner (blue)
glVertex3f( 0.0f, 4.5f, 0.0f ); // Third corner of the triangle
glEnd(); // No more triangles...

glFlush();
}

int main( int argc, char **argv )
{
int ok; // Flag telling if the window was opened
int running; // Flag telling if the program is running

// Initialize GLFW
glfwInit();

// Open window
ok = glfwOpenWindow(
640, 480, // Width and height of window
8, 8, 8, // Number of red, green, and blue bits for color buffer
8, // Number of bits for alpha buffer
24, // Number of bits for depth buffer (Z-buffer)
0, // Number of bits for stencil buffer
GLFW_WINDOW // We want a desktop window (could be GLFW_FULLSCREEN)
);

// If we could not open a window, exit now
if( !ok )
{
glfwTerminate();
return 0;
}

// Set window title
glfwSetWindowTitle( "Demo" );

// Enable sticky keys
glfwEnable( GLFW_STICKY_KEYS );

Init();

// Main rendering loop
do
{
CalculateFrameRate();

// Call our rendering function
Draw();

// Swap front and back buffers (we use a double buffered display)
glfwSwapBuffers();

// Check if the escape key was pressed, or if the window was closed
running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED );
}
while( running );

// Terminate GLFW
glfwTerminate();

// Exit program
return 0;
}

void CalculateFrameRate()
{
static float framesPerSecond = 0.0f; // This will store our fps
static float lastTime = 0.0f; // This will hold the time from the last frame
static char strFrameRate[50] = {0}; // We will store the string here for the window title
float currentTime = GetTickCount() * 0.001f;
++framesPerSecond;
if( currentTime - lastTime > 1.0f )
{
lastTime = currentTime;
sprintf(strFrameRate, "Current Frames Per Second: %d", int(framesPerSecond));
glfwSetWindowTitle( strFrameRate );
framesPerSecond = 0;
}
}



As you can see, that's it! THere's not much you have to do to get up and running. Not only that, I'm sure you could optimize the program flow of it to make it a lot better. That example is just one of those, beginning concept examples. You can greatly expand it.

The main reason I like GLFW is that it takes care of all the details that you would otherwise have to make for your game. Originally I had written my own window class and OpenGL setup code, but it was Win32 specifc. GLFW takes care of it all, much like SDL and GLUT. I personally like this GLFW over SDL already and I've used SDL for quite some time now. It is just a OpenGL wrapper compared to something like SDL that adds in all the SDL specific stuff.

If you have any other questions or comments, feel free to ask. I hope I have covered everything, but I might have missed a few things.

- Drew

Share this post


Link to post
Share on other sites
Dang you GameDev! That AP was me.

If you are just writing for Win32, take Oluseyi's post into consideration, he's right. I too do not believe that DX will go away anytime soon. It may stop being supported in a few years due to some new break though, but it will not just become useless. Look at DOS - it's had its days yet it still is used, even though WinXP uses it less than previous OS's.

However, I would still use something like GLFW for ease of development and if you were going to have any intrests of going cross platform. I happen to be using DirectInput with my GLFW as a matter of fact. I can get back to you later on during development how it goes with GLFW.

However Oluseyi, when you say
Quote:
Consequently, it seems that you are falling victim to hype and MS-bashing, causing you unnecessary apprehension and wasting your time. Your projects are suffering while you resolve this non-issue.
I think it is in part Microsofts fault as well. I mean the whole deal with the new Visual Studio 2005 Express not comming with the default Win32 components really has a lot of people wary. I mean look at all the people who freak out because they cannot find "windows.h", even though all you have to do is download the platform SDK. I also believe a thread was started a while back relating how much Win32 will be used in the future and how .NET is becoming the more norm. I don't know, it's just one of those insecurity things. I am not worried about it at all though.

- Drew

Share this post


Link to post
Share on other sites
Oluseyi:

Your first post was spot on. Thank you for the relevant information.

Drew:

That is very good information, it looks like GLFW is very easy to use. I also want it to be feature-rich, which is one reason I like DirectX. I too am struggling with the "support" with MS products, as you say. With recent releases of DX SDK's, I can't use the Winter DX9 SDK because I use VC++ 6.0. I just happen to like that IDE. So I had to roll back to the october SDK just so I could use 6.0 IDE. That seems like a strange way to support your past products to me. VC6.0 isn't that old, and is the Winter DX9 SDK really that different from the October one? Anyways, thats just one example that comes to mind.

One thing that keeps pulling me back to DX, though, is the number of features, esp. in D3DX support (like meshes, etc). Very nice stuff. I would very much like to hear how using either DInput or the functionality in GLFW goes for you. What type of game are you looking to make?

The main reason I bring this whole thing up is that I would like to work on my game idea long term, and be able to constantly add content instead of rewrite core technologies. I don't relish the idea of having to at some point write up a new core portion of the engine just because the API I chose way back in the "before-time" (now) is no longer in favor. I suppose I could just use that as an excuse to learn a new API, but I'd like to _try_ to avoid it if possible.

Cheers,

roger_hq

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
However Oluseyi, ... I think it is in part Microsoft's fault as well. I mean the whole deal with the new Visual Studio 2005 Express not coming with the default Win32 components really has a lot of people wary.
Would you, by any chance, happen to mean Visual Studio 2005 Express Beta? Because, as far as I know, there is no information to suggest that the final release will not either include the Platform SDK or automatically invoke a PSDK download. People are always looking for reasons to freak out when it comes to Microsoft; that some people interpret the minimalistic Express Beta component installs as a sign of a policy shift says nothing of import.

Quote:
I also believe a thread was started a while back relating how much Win32 will be used in the future and how .NET is becoming the more norm.
Is that supposed to be a bad thing? I mean, do you actually like using Win32?

I think too many people are speaking based on inadequate information/experience, or even ignorance. You try implementing a ReBar control hosting dynamic toolbars in Win32, then compare to doing the same in .NET. Remember, Win32 doesn't exist just to piggyback games (which is why I discard most gripes from GameDev).

You don't see anybody on Experts Exchange, The Code Project or DevX whining about the imminent "demise" of Win32, and with good reason.

Share this post


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

  • Advertisement