Sign in to follow this  
Seabolt

OpenGL OpenGL is acting strangely

Recommended Posts

Hey guys,

So I'm currently rendering a triangle in OpenGL 2.0. I can get it to render but there are some strange things afoot that shouldn't be.

First strange behavior:
I'm required to use glFlush. Without it the screen will just show white when I clear to a dark blue. I will see my triangle if the last frame as I close the program. I know I shouldn't have to call glFlush to do that so I'm wondering why the GPU isn't executing the calls without it. I've tested this on multiple computers, and the behavior is the same, so this isn't a GPU specific issue.

Second strange behavior:
I recently bought a new laptop and moved everything over to it. The only changes I made program wise is I removed GLUT from the project, and took out all related dependencies. I also upgraded from VS 2008 to VS 2010. Also the laptop is 64 bit vs the previous 32 bit. With those being the only changes, my SwapBuffers() call will return false every time, BUT it will still render. I can resize my screen and move it and the triangle is still there and is reacting to the changes. I called GetLastError() and it returns 0, so the thread isn't posting any errors, yet it still returns false every frame.

Now I really don't want to go forward with these issues because I'd rather not build on a foundation of mud, so any help would be appreciated.

Here's the various code (its spread across a couple of modules):

[code]
//////////////////////////////////////////////////////////////////////////
// WinMain.cpp
// - Used to create the main loop of execution
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// Includes
//////////////////////////////////////////////////////////////////////////
#include <Windows.h>

#include "../Graphics/CDeviceManager.h"
#include "../Game/CGame.h"
//////////////////////////////////////////////////////////////////////////
// Global Variables
//////////////////////////////////////////////////////////////////////////

HWND g_hWnd = NULL; // The copy of the current handle to the window
HINSTANCE g_hInstance = NULL; // The current copy of the instance of this program
int g_nWindowWidth = 1280;
int g_nWindowHeight = 720;
CWindow g_cWindow;

//////////////////////////////////////////////////////////////////////////
// Forward Declarations
//////////////////////////////////////////////////////////////////////////

// MainWndProc
// - The callback function for the message loop windows uses
LRESULT CALLBACK
MainWndProc( HWND handleWindow, // The handle for the window
UINT unMessage, // The message ID for this iteration
WPARAM wParam, // Additional parameters
LPARAM lParam ); // Additional parameters

//////////////////////////////////////////////////////////////////////////

// WinMain
// - The first function called by windows; serves as the main loop for the program
int APIENTRY
WinMain( HINSTANCE hInstance, // The current instance of the program
HINSTANCE hPrevInstance, // The previous instance of the program
LPSTR lpCmdLine, // Any command line arguments
int nCmdCount ) // How many arguments the are
{
// Save our global copies
g_hInstance = hInstance;

// Create a window
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wcex.lpfnWndProc = (WNDPROC)MainWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("Thunderclad Engine"); // Should be unique
wcex.hIconSm = NULL;

// Select window styles
UINT unStyle,unStyleX;
unStyleX = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
unStyle = WS_OVERLAPPEDWINDOW;

// Describe our window placement
WINDOWPLACEMENT wndPlacement;
wndPlacement.length = sizeof(WINDOWPLACEMENT);
wndPlacement.ptMaxPosition.x = 0;
wndPlacement.ptMaxPosition.y = 0;
wndPlacement.ptMinPosition.x = 0;
wndPlacement.ptMinPosition.y = 0;
wndPlacement.rcNormalPosition.bottom = g_nWindowHeight;
wndPlacement.rcNormalPosition.left = 0;
wndPlacement.rcNormalPosition.top = 0;
wndPlacement.rcNormalPosition.right = g_nWindowWidth;

// Create our instance of our main window
g_cWindow.Init( g_hWnd,
wndPlacement,
&wcex,
unStyle,
unStyleX,
g_nWindowWidth,
g_nWindowHeight,
TEXT("Thunderclad Engine"),
g_hInstance );

// Initialize the game here
CGame::GetInstance()->Initialize();

// Start the message loop
MSG msg;
while( CGame::GetInstance()->IsGameActive() )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT )
{
break;
}

TranslateMessage( &msg );
DispatchMessage( &msg );
}
else if( CGame::GetInstance()->IsGameActive() )
{
CGame::GetInstance()->Update();
CGame::GetInstance()->Render();
}
}

// Clean up our classes
CGame::GetInstance()->Destroy();
CDeviceManager::GetInstance()->Destroy();
g_cWindow.Destroy();

// return from the program
return msg.wParam;
}

// MainWndProc
// - This will be the message proc for the main window
LRESULT CALLBACK
MainWndProc( HWND handleWindow, // The handle to the window
UINT unMessage, // The message to process
WPARAM wParam, // An additional parameter
LPARAM lParam ) // An additional parameter
{
g_hWnd = handleWindow;

switch( unMessage )
{
case WM_CREATE:
g_cWindow.SetWindowHandle( handleWindow );
g_cWindow.SetHDC( GetDC( handleWindow ) );
CDeviceManager::GetInstance()->Initialize( &g_cWindow );
break;

case WM_ERASEBKGND:
return false;

case WM_SIZE:
// Resize the window
CDeviceManager::GetInstance()->Resize( LOWORD( lParam ),
HIWORD( lParam ) );
return 0;
break;
case WM_CLOSE:
// Free up resources if the red x is pressed
CGame::GetInstance()->Destroy();
CDeviceManager::GetInstance()->Destroy();
g_cWindow.Destroy();
break;
default:
return DefWindowProc( handleWindow,
unMessage,
wParam,
lParam );
}

return 0;
}[/code]


[code]

//////////////////////////////////////////////////////////////////////////
// CWindow.cpp
// - Defines the functions for our window class
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// Includes
//////////////////////////////////////////////////////////////////////////
#include "CWindow.h"
#include <Windows.h>
#include <tchar.h>
#include <assert.h>

//////////////////////////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////////////////////////////////
CWindow::CWindow()
{
m_handleWindow = NULL;
m_handleInstance = NULL;
m_bIsFullScreen = false;
m_wndPlacement;
m_wndClassDescription;

// Zero out our structures
ZeroMemory( &m_wndClassDescription, sizeof( WNDCLASSEX ) );
ZeroMemory( &m_wndPlacement, sizeof( WINDOWPLACEMENT ) );
}

//////////////////////////////////////////////////////////////////////////
// Destructor
//////////////////////////////////////////////////////////////////////////
CWindow::~CWindow()
{
// Free any resources allocated
}

//////////////////////////////////////////////////////////////////////////
// Function Definitions
//////////////////////////////////////////////////////////////////////////

void
CWindow::Init( HWND &out_handleWindow, // The handle to the window
WINDOWPLACEMENT in_wndPlacement, // The class that describes the window's placement
const WNDCLASSEX* in_wndClassDescription, // The class that describes the class's functionality
UINT in_unWindowStyle, // The window style
UINT in_unWindowExStyle, // The windowEx style
int in_nWindowWidth, // The window width
int in_nWindowHeight, // The window height
LPCWSTR in_szProgramName, // The name of the program
HINSTANCE in_handleCurrentInstance ) // The current instance of the program
{

// Store our copies
SetWindowWidth( in_nWindowWidth );
SetWindowHeight( in_nWindowHeight );
IsFullScreen( false );

// Store our copies of relevant info
m_wndClassDescription = *in_wndClassDescription;
m_handleInstance = in_handleCurrentInstance;
m_lpWindowName = in_szProgramName;
m_unWindowStyle = in_unWindowStyle;
m_unWindowStyleEX = in_unWindowExStyle;

// First we must register the class
assert( RegisterClassEx( &m_wndClassDescription ) != 0 );

RECT windowRect; // Grabs Rectangle Upper Left / Lower Right Values
windowRect.left=(long)0; // Set Left Value To 0
windowRect.right=(long)GetWindowWidth(); // Set Right Value To Requested Width
windowRect.top=(long)0; // Set Top Value To 0
windowRect.bottom=(long)GetWindowHeight(); // Set Bottom Value To Requested Height

// Get a pixel perfect window
AdjustWindowRectEx( &windowRect, m_unWindowStyle, FALSE, m_unWindowStyleEX );

// Then we must create the window from the data provided;
SetWindowHandle( CreateWindowEx( m_unWindowStyleEX,
m_wndClassDescription.lpszClassName,
in_szProgramName,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | in_unWindowStyle,
0,
0,
GetWindowWidth(),
GetWindowHeight(),
NULL,
NULL,
m_handleInstance,
NULL ) );

assert( GetWindowHandle() != NULL );


// Show the window and start updating it
ShowWindow( GetWindowHandle(), SW_SHOW );
UpdateWindow( GetWindowHandle() );
}

// ReCreateWindow
void
CWindow::ReCreateWindow()
{
// Destroy this window and Unregister it
assert( DestroyWindow( m_handleWindow ) != NULL );
WNDCLASSEX temp = m_wndClassDescription;
UnregisterClass( m_wndClassDescription.lpszClassName, m_handleInstance );

// Re register and position it
// First we must register the class
assert( RegisterClassEx( &m_wndClassDescription ) != 0 );

RECT windowRect; // Grabs Rectangle Upper Left / Lower Right Values
windowRect.left=(long)0; // Set Left Value To 0
windowRect.right=(long)GetWindowWidth(); // Set Right Value To Requested Width
windowRect.top=(long)0; // Set Top Value To 0
windowRect.bottom=(long)GetWindowHeight(); // Set Bottom Value To Requested Height

// Get a pixel perfect window
AdjustWindowRectEx( &windowRect, m_unWindowStyle, FALSE, m_unWindowStyleEX);

m_handleWindow = CreateWindowEx( m_unWindowStyleEX,
m_wndClassDescription.lpszClassName,
m_lpWindowName,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | m_unWindowStyle,
0,
0,
GetWindowWidth(),
GetWindowHeight(),
NULL,
NULL,
m_handleInstance,
NULL );
UINT error = GetLastError();
assert( m_handleWindow != NULL );


// Show the window and start updating it
ShowWindow( m_handleWindow, SW_SHOW );
UpdateWindow( m_handleWindow );
}

// Destroy
// - Destroys this window
void
CWindow::Destroy()
{
if( m_handleWindow != NULL )
{
// Destroys this window and removes it from the message pump
DestroyWindow( m_handleWindow );
m_handleWindow = NULL;
}

UnregisterClass( m_wndClassDescription.lpszClassName, m_handleInstance );
}

[/code]


[code]

// COpenGLDeviceManager.cpp
// - This file will define all methods declared in COpenGLDeviceManager.h

//////////////////////////////////////////////////////////////////////////
// Includes
//////////////////////////////////////////////////////////////////////////
#include "COpenGLDeviceManager.h"

//////////////////////////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////////////////////////////////
COpenGLDeviceManager::COpenGLDeviceManager()
{
//////////////////////////////////////////////////////////////////////////
// Platform Specific initialization (Windows)
#if USING_WINDOWS
m_handleWindowHandle = NULL;
m_handleGLRenderContext = NULL;
m_handleDeviceContext = NULL;

ZeroMemory( &m_tPixelFormat, sizeof(PIXELFORMATDESCRIPTOR) );
#endif
//////////////////////////////////////////////////////////////////////////
}


//////////////////////////////////////////////////////////////////////////
// Destructor
//////////////////////////////////////////////////////////////////////////
COpenGLDeviceManager::~COpenGLDeviceManager()
{
m_handleWindowHandle = NULL;
m_handleDeviceContext = NULL;
m_handleGLRenderContext = NULL;

ZeroMemory( &m_tPixelFormat, sizeof( PIXELFORMATDESCRIPTOR ) );
}

//////////////////////////////////////////////////////////////////////////
// TEMP REMOVE THIS CODE
#include <math.h>
void BuildPerspProjMat(float *m, float fov, float aspect,
float znear, float zfar)
{
float xymax = znear * tan(fov);
float ymin = -xymax;
float xmin = -xymax;

float width = xymax - xmin;
float height = xymax - ymin;

float depth = zfar - znear;
float q = -(zfar + znear) / depth;
float qn = -2 * (zfar * znear) / depth;

float w = 2 * znear / width;
w = w / aspect;
float h = 2 * znear / height;

m[0] = w;
m[1] = 0;
m[2] = 0;
m[3] = 0;

m[4] = 0;
m[5] = h;
m[6] = 0;
m[7] = 0;

m[8] = 0;
m[9] = 0;
m[10] = q;
m[11] = -1;

m[12] = 0;
m[13] = 0;
m[14] = qn;
m[15] = 0;
}
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// Function Definitions
//////////////////////////////////////////////////////////////////////////
STATUS
COpenGLDeviceManager::Initialize( CWindow* programWindow )
{
m_bIsFullScreen = programWindow->IsFullScreen();

//////////////////////////////////////////////////////////////////////////
// Platform Specific Initialization (Windows)
#if USING_WINDOWS

// Store the HWND
m_handleWindowHandle = programWindow->GetWindowHandle();

// Do a NULL check if we are in Debug
ASSERT_NULL( m_handleWindowHandle );

// Get the Device Context
m_handleDeviceContext = programWindow->GetHDC();

// Null check the DC
ASSERT_NULL( m_handleDeviceContext );

//////////////////////////////////////////////////////////////////////////
// Set the pixel format
m_tPixelFormat.nSize = sizeof( PIXELFORMATDESCRIPTOR ); // Size of the PFD
m_tPixelFormat.nVersion = 1; // Set the version number
m_tPixelFormat.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
m_tPixelFormat.iPixelType = PFD_TYPE_RGBA; // Set the color format
m_tPixelFormat.cColorBits = 32; // Set the color depth
m_tPixelFormat.cDepthBits = 24; // Set the depth buffer depth
m_tPixelFormat.iLayerType = PFD_MAIN_PLANE; // Set the layer for the app

// See if there is a pixel format that will match our requests
int nPixelFormat = 0;
ASSERT_FALSE( nPixelFormat = ChoosePixelFormat( m_handleDeviceContext,
&m_tPixelFormat ) );

ASSERT_FALSE( SetPixelFormat( m_handleDeviceContext,
nPixelFormat,
&m_tPixelFormat ) );

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// So far so good... Now we try to create our RenderContext (HRC)
HGLRC tempContext = wglCreateContext( m_handleDeviceContext );
ASSERT_NULL( tempContext );
DWORD pleaseBeIt = GetLastError();

// See if the tempContext will work
ASSERT_FALSE( wglMakeCurrent( m_handleDeviceContext, tempContext ) ); CHECK();

pleaseBeIt = GetLastError();

//GLenum error = glewInit();
//if( error != GLEW_OK )
//{
// fprintf(stderr, "Error: %s\n", glewGetErrorString(error));
//}

//DWORD lastError = GetLastError();

if( false )//wglewIsSupported( "WGL_ARB_create_context" ) == 1 )
{
//lastError = GetLastError();
//// Define our attributes for using OpenGL 3.0 and forward
//int attribs[] = {
// WGL_CONTEXT_MAJOR_VERSION_ARB, 3,//we want a 3.0 context
// WGL_CONTEXT_MINOR_VERSION_ARB, 1,
// //and it shall be forward compatible so that we can only use up to date functionality
// WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
// 0}; //zero indicates the end of the array

// lastError = GetLastError();
// m_handleGLRenderContext = wglCreateContextAttribsARB( m_handleDeviceContext, 0, attribs ); CHECK();
// ASSERT_NULL( m_handleGLRenderContext );
// ASSERT_FALSE( wglMakeCurrent( NULL, NULL ) ); lastError = GetLastError(); // CHECK();
// ASSERT_FALSE( wglDeleteContext( tempContext ) ); // CHECK();
// ASSERT_FALSE( wglMakeCurrent( m_handleDeviceContext, m_handleGLRenderContext ) ); CHECK();
}
else // If we can't use 3.1
{
m_handleGLRenderContext = tempContext;
}
//////////////////////////////////////////////////////////////////////////

TVector3F position;
TMatrixF rotation;
rotation.MakeIdentity();
position.X = position.Y = position.Z = 0.0f;
m_tempCamera.Initialize( m_tempCamera.CreateViewMatrix( position, rotation ),
m_tempCamera.CreateProjectionMatrix( 1280 / 720,
45, 10, 100 ), CCamera::FREE_ROAM );
#endif

return OK;
}

STATUS
COpenGLDeviceManager::Destroy()
{
//////////////////////////////////////////////////////////////////////////
// Platform Specific Destroy
#if USING_WINDOWS
// Check to see if we can safely release and delete our RenderContext
if( m_handleGLRenderContext )
{
ASSERT_FALSE( wglMakeCurrent( m_handleDeviceContext, NULL ) );
ASSERT_FALSE( wglDeleteContext( m_handleGLRenderContext ) );
m_handleGLRenderContext = NULL;
}

// Check and see if we can safely release our DeviceContext
if( m_handleDeviceContext )
{
ASSERT_FALSE( ReleaseDC( m_handleWindowHandle, m_handleDeviceContext ) );
m_handleDeviceContext = NULL;
}
#else
#endif

return OK;
}

STATUS
COpenGLDeviceManager::Resize( i4 nScreenWidth, i4 nScreenHeight )
{
CHECK();
glViewport (0, 0, nScreenWidth, nScreenHeight); CHECK();

glMatrixMode( GL_PROJECTION ); CHECK();
glLoadMatrixf( m_tempCamera.GetProjectionMatrix().MatrixArray ); CHECK();
glMatrixMode( GL_MODELVIEW ); CHECK();
glLoadMatrixf( m_tempCamera.GetViewMatrix().MatrixArray );

return OK;
}

STATUS
COpenGLDeviceManager::Present()
{
//////////////////////////////////////////////////////////////////////////
// Platform Specific Present
#if USING_WINDOWS

CHECK();
glFlush(); CHECK();
DWORD test = GetLastError();
SwapBuffers( m_handleDeviceContext ); CHECK();

// Invalidate the window to draw
RECT clientRect;
GetClientRect( m_handleWindowHandle, &clientRect );
InvalidateRect( m_handleWindowHandle, &clientRect, FALSE );
#else
#endif
//////////////////////////////////////////////////////////////////////////
return OK;
}

STATUS
COpenGLDeviceManager::Clear( i4 unBuffersToClear )
{
//////////////////////////////////////////////////////////////////////////
// Determine which buffers to clear
GLbitfield glBitToClear = 0;
if( COLOR_BUFFER_MASK( unBuffersToClear ) )
{
glBitToClear |= GL_COLOR_BUFFER_BIT;
}

if( DEPTH_BUFFER_MASK( unBuffersToClear ) )
{
glBitToClear |= GL_DEPTH_BUFFER_BIT;
}

if( STENCIL_BUFFER_MASK( unBuffersToClear ) )
{
glBitToClear |= GL_STENCIL_BUFFER_BIT;
}
//////////////////////////////////////////////////////////////////////////

glClearColor(0.0f, 0.2f, 0.4f, 1.0f); CHECK(); // The color to clear the background to

// Finally we can clear the buffers
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

return OK;
}
[/code]


[code]

// COpenGLRenderer.cpp
// - This class will define the functions declared in COpenGLRenderer.h

//////////////////////////////////////////////////////////////////////////
// Includes
//////////////////////////////////////////////////////////////////////////
#include "COpenGLRenderer.h"
#include "Vertices.h"

//////////////////////////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////////////////////////////////
COpenGLRenderer::COpenGLRenderer()
{

}

//////////////////////////////////////////////////////////////////////////
// Destructor
//////////////////////////////////////////////////////////////////////////
COpenGLRenderer::~COpenGLRenderer()
{

}

//////////////////////////////////////////////////////////////////////////
// Function Definitions
//////////////////////////////////////////////////////////////////////////

// Initialize
// - This will handle all the initialization needed for the renderer
STATUS
COpenGLRenderer::Initialize()
{
CHECK();
glEnable(GL_DEPTH_TEST); CHECK(); // Enable depth testing
glDepthFunc( GL_LEQUAL ); CHECK(); // Reject anything less than or equal to the current depth
glClearDepth( 1.0f ); CHECK(); // We clear to full depth
glClearStencil( 0 ); CHECK(); // We clear the stencil buffer to false
glCullFace(GL_BACK); CHECK(); // Enable culling
glClearColor(0.0f, 0.2f, 0.4f, 1.0f); CHECK(); // The color to clear the background to
return OK;
}

// Destroy
// - This will free all the memory used by the renderer
STATUS
COpenGLRenderer::Destroy()
{
return OK;
}

// DrawBuffer
// - This will draw a single vertex buffer
void
COpenGLRenderer::DrawVertexBuffer( CVertexBuffer* pBufferToDraw )
{
glLoadIdentity();
glPushMatrix();
glEnableClientState( GL_VERTEX_ARRAY ); CHECK();
glEnableClientState( GL_NORMAL_ARRAY ); CHECK();
glEnableClientState( GL_COLOR_ARRAY ); CHECK();

glVertexPointer(3,
GL_FLOAT,
pBufferToDraw->GetDeclaration()->GetSizeOfVertex(),
pBufferToDraw->GetVertices() ); CHECK();
glNormalPointer( GL_FLOAT,
pBufferToDraw->GetDeclaration()->GetSizeOfVertex(),
static_cast<uchar1*>(pBufferToDraw->GetVertices()) + sizeof( f4 ) * 3 ); CHECK();
glColorPointer( 4,
GL_FLOAT,
pBufferToDraw->GetDeclaration()->GetSizeOfVertex(),
static_cast<uchar1*>(pBufferToDraw->GetVertices()) + sizeof( f4 ) * 6 ); CHECK();

glDrawArrays( GL_TRIANGLES, 0, 3 ); CHECK();
glPopMatrix();
}


[/code]


The CHECK() macro just checks the glGetError value for non zero, none of these are being hit.

Share this post


Link to post
Share on other sites
Hmmm you might be on to something there. The major difference is that the PIXELFORMATDESCRIPTOR that I'm storing has a dwFlags value of 37 and the one returned by DescribePixelFormat is 32804. I zero the memory out on the structure before I set the format, so is that just something that Windows does when I set it trying to find an appropriate value? That's a very vague question I know.

Share this post


Link to post
Share on other sites
PFD dwFlags 37 is :
PFD_DOUBLEBUFFER
PFD_DRAW_TO_WINDOW
PFD_SUPPORT_OPENGL


32804 is:
PFD_DRAW_TO_WINDOW
PFD_SUPPORT_OPENGL
PFD_SUPPORT_COMPOSITION

So it appears that your window doesn't support double buffer?

Share this post


Link to post
Share on other sites
ChoosePixelFormat doesn't actually guarantee that you're going to get the format you ask for; instead you're going to get a "best match" format so you should always double-check that what you get is what you actually want. It's also possible to bypass ChoosePixelFormat, loop through the formats available and pick one yourself (with a possible fallback to ChoosePixelFormat if you can't find what you want).

Share this post


Link to post
Share on other sites
That's strange that it's not supporting double[b] [/b]buffering... I'm going to search for reasons as to why that might be, but any suggestions you guys have would be appreciated as well :)

Share this post


Link to post
Share on other sites
First thing I'd do is double-check your driver - it may be a generic Microsoft or OEM driver that doesn't come with OpenGL support, so you might need a driver update. Assuming that's OK and you still don't get double-buffering, then try looping through the pixel formats as I suggested and ensure that your driver is actually exposing one that supports double buffering.

Try those first, then come back with the info and we'll see where to go from there.

Share this post


Link to post
Share on other sites
So I can find a couple of PixelFormats that have double buffering, but they all had strange color bit information. Idk if that's my fault or if for some reason my IntelHD Graphics card really can't support RGBA pixel format or 32bit color buffer. It seems fairly unlikely, especially since it's really new and I updated my drivers... :/

Share this post


Link to post
Share on other sites
Actually it looks like I can get all my desired functionality. Why did ChoosePixelFormat play with my emotions so? Thanks you very much mhagain, I've been fighting this bug for a month now, for something as trivial as this. Hahaha it makes me feel stupid as hell.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
      628345
    • Total Posts
      2982202
  • Similar Content

    • By test opty
      Hi all,
       
      I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?
       
       
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Thanks, 
      Dejay Hextrix 
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
  • Popular Now