• Advertisement
Sign in to follow this  

OpenGL OpenGL is acting strangely

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

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):


//////////////////////////////////////////////////////////////////////////
// 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;
}





//////////////////////////////////////////////////////////////////////////
// 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 );
}






// 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;
}





// 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();
}





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
Advertisement
That sounds an awful lot like you're getting a single-buffered context. I know you're asking for double-buffered, but you should probably use DescribePixelFormat just to verify.

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
case WM_ERASEBKGND:
return false;

http://www.opengl.org/wiki/Platform_specifics:_Windows#It.27s_flickering.21_Why.3F

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 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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By LifeArtist
      Good Evening,
      I want to make a 2D game which involves displaying some debug information. Especially for collision, enemy sights and so on ...
      First of I was thinking about all those shapes which I need will need for debugging purposes: circles, rectangles, lines, polygons.
      I am really stucked right now because of the fundamental question:
      Where do I store my vertices positions for each line (object)? Currently I am not using a model matrix because I am using orthographic projection and set the final position within the VBO. That means that if I add a new line I would have to expand the "points" array and re-upload (recall glBufferData) it every time. The other method would be to use a model matrix and a fixed vbo for a line but it would be also messy to exactly create a line from (0,0) to (100,20) calculating the rotation and scale to make it fit.
      If I proceed with option 1 "updating the array each frame" I was thinking of having 4 draw calls every frame for the lines vao, polygons vao and so on. 
      In addition to that I am planning to use some sort of ECS based architecture. So the other question would be:
      Should I treat those debug objects as entities/components?
      For me it would make sense to treat them as entities but that's creates a new issue with the previous array approach because it would have for example a transform and render component. A special render component for debug objects (no texture etc) ... For me the transform component is also just a matrix but how would I then define a line?
      Treating them as components would'nt be a good idea in my eyes because then I would always need an entity. Well entity is just an id !? So maybe its a component?
      Regards,
      LifeArtist
    • By QQemka
      Hello. I am coding a small thingy in my spare time. All i want to achieve is to load a heightmap (as the lowest possible walking terrain), some static meshes (elements of the environment) and a dynamic character (meaning i can move, collide with heightmap/static meshes and hold a varying item in a hand ). Got a bunch of questions, or rather problems i can't find solution to myself. Nearly all are deal with graphics/gpu, not the coding part. My c++ is on high enough level.
      Let's go:
      Heightmap - i obviously want it to be textured, size is hardcoded to 256x256 squares. I can't have one huge texture stretched over entire terrain cause every pixel would be enormous. Thats why i decided to use 2 specified textures. First will be a tileset consisting of 16 square tiles (u v range from 0 to 0.25 for first tile and so on) and second a 256x256 buffer with 0-15 value representing index of the tile from tileset for every heigtmap square. Problem is, how do i blend the edges nicely and make some computationally cheap changes so its not obvious there are only 16 tiles? Is it possible to generate such terrain with some existing program?
      Collisions - i want to use bounding sphere and aabb. But should i store them for a model or entity instance? Meaning i have 20 same trees spawned using the same tree model, but every entity got its own transformation (position, scale etc). Storing collision component per instance grats faster access + is precalculated and transformed (takes additional memory, but who cares?), so i stick with this, right? What should i do if object is dynamically rotated? The aabb is no longer aligned and calculating per vertex min/max everytime object rotates/scales is pretty expensive, right?
      Drawing aabb - problem similar to above (storing aabb data per instance or model). This time in my opinion per model is enough since every instance also does not have own vertex buffer but uses the shared one (so 20 trees share reference to one tree model). So rendering aabb is about taking the model's aabb, transforming with instance matrix and voila. What about aabb vertex buffer (this is more of a cosmetic question, just curious, bumped onto it in time of writing this). Is it better to make it as 8 points and index buffer (12 lines), or only 2 vertices with min/max x/y/z and having the shaders dynamically generate 6 other vertices and draw the box? Or maybe there should be just ONE 1x1x1 cube box template moved/scaled per entity?
      What if one model got a diffuse texture and a normal map, and other has only diffuse? Should i pass some bool flag to shader with that info, or just assume that my game supports only diffuse maps without fancy stuff?
      There were several more but i forgot/solved them at time of writing
      Thanks in advance
    • By RenanRR
      Hi All,
      I'm reading the tutorials from learnOpengl site (nice site) and I'm having a question on the camera (https://learnopengl.com/Getting-started/Camera).
      I always saw the camera being manipulated with the lookat, but in tutorial I saw the camera being changed through the MVP arrays, which do not seem to be camera, but rather the scene that changes:
      Vertex Shader:
      #version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(aPos, 1.0f); TexCoord = vec2(aTexCoord.x, aTexCoord.y); } then, the matrix manipulated:
      ..... glm::mat4 projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); ourShader.setMat4("projection", projection); .... glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp); ourShader.setMat4("view", view); .... model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f)); ourShader.setMat4("model", model);  
      So, some doubts:
      - Why use it like that?
      - Is it okay to manipulate the camera that way?
      -in this way, are not the vertex's positions that changes instead of the camera?
      - I need to pass MVP to all shaders of object in my scenes ?
       
      What it seems, is that the camera stands still and the scenery that changes...
      it's right?
       
       
      Thank you
       
    • By dpadam450
      Sampling a floating point texture where the alpha channel holds 4-bytes of packed data into the float. I don't know how to cast the raw memory to treat it as an integer so I can perform bit-shifting operations.

      int rgbValue = int(textureSample.w);//4 bytes of data packed as color
      // algorithm might not be correct and endianness might need switching.
      vec3 extractedData = vec3(  rgbValue & 0xFF000000,  (rgbValue << 8) & 0xFF000000, (rgbValue << 16) & 0xFF000000);
      extractedData /= 255.0f;
    • By Devashish Khandelwal
      While writing a simple renderer using OpenGL, I faced an issue with the glGetUniformLocation function. For some reason, the location is coming to be -1.
      Anyone has any idea .. what should I do?
  • Advertisement