Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


CornyKorn

Member Since 09 Aug 2005
Offline Last Active May 15 2014 03:34 PM

Topics I've Started

Windows OpenGL Initialization Questions

24 September 2013 - 09:37 AM

Hi,
I was wondering if anyone could answer a few questions I have about properly setting up an OpenGL 4.1 context on Windows. I scrapped together two quick code samples on my computer one using GLFW/GLEW and another creating my own window and using GLEW.

I ran both code samples through gDEBugger and I'm a little confused by the results. Based on the way I set up my window in both of the samples below I expected to only see a "Front Buffer" and "Back Buffer" when I viewed the context in gDEBugger. Instead I am seeing a depth, back, front, and four auxiliary buffers. Do I have any control over the creation of those buffers?

The other question I have is if I'm properly setting up my OpenGL context for Windows. The one issue I seem to be having is that if I specify WGL_CONTEXT_DEBUG_BIT_ARB in the sample where I create my own window it doesn't properly create a context.
 
Posted this over at the OpenGL forums as well.
Thanks for any help.
 
GLFW/GLEW:

#define GLEW_STATIC
#define WIN32_LEAN_AND_MEAN
 
#include <Windows.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <GLM/glm.hpp>
#include "Debugging/glDebugging.h"
 
int main( int argc, char* argv[] )
{
        if( !glfwInit() )
                return EXIT_FAILURE;
 
        // define glfw window hints
#if defined( _DEBUG )
        glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE );
#endif
        glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
        glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
        glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
        glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 );
        glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, 1 );
        glfwWindowHint( GLFW_DEPTH_BITS, 0 );
        glfwWindowHint( GLFW_STENCIL_BITS, 0 );
        glfwWindowHint( GLFW_ACCUM_RED_BITS, 0 );
        glfwWindowHint( GLFW_ACCUM_GREEN_BITS, 0 );
        glfwWindowHint( GLFW_ACCUM_BLUE_BITS, 0 );
        glfwWindowHint( GLFW_ACCUM_ALPHA_BITS, 0 );
        glfwWindowHint( GLFW_AUX_BUFFERS, 0 );
 
        // open a window with GLFW
        GLFWwindow* pWindow = glfwCreateWindow( 640, 360, "LearnGL", nullptr, nullptr );
        if( pWindow == nullptr )
        {
                glfwTerminate();
                return EXIT_FAILURE;
        }
 
        glfwMakeContextCurrent( pWindow );
 
        // initialize GLEW
        glewExperimental = GL_TRUE;
        if( glewInit() != GLEW_OK )
        {
                glfwTerminate();
                return EXIT_FAILURE;
        }
 
        if( !GLEW_VERSION_4_1 )
        {
                glfwTerminate();
                return EXIT_FAILURE;
        }
 
#if defined( _DEBUG )
        GL::InitializeDebugging();
#endif
 
        GLuint frameBuffer;
        GLuint colorBufferTexture;
 
        glGenTextures( 1, &colorBufferTexture );
 
        // Set up texture
        glActiveTexture( GL_TEXTURE0 );
        glBindTexture( GL_TEXTURE_2D, colorBufferTexture );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0 );
        glTexImage2D( GL_TEXTURE_2D, GLint( 0 ), GL_RGBA8, GLsizei( 640 ), GLsizei( 360 ), 0,
                GL_RGBA, GL_UNSIGNED_BYTE, nullptr );
        glBindTexture( GL_TEXTURE_2D, 0 );
 
        glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
 
        // Set up frame buffer
        glGenFramebuffers( 1, &frameBuffer );
        glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer );
        glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorBufferTexture, 0 );
        glBindFramebuffer( GL_FRAMEBUFFER, 0 );
 
        while( !glfwWindowShouldClose( pWindow ) )
        {
                // Viewport setup
                int width = 0;
                int height = 0;
 
                glfwGetWindowSize( pWindow, &width, &height );
                glViewport( 0, 0, width, height );
 
                // Clear render targets
                glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer );
                glClearBufferfv( GL_COLOR, 0, &glm::vec4( 1.0f, 0.0f, 5.0f, 1.0f )[0] );
 
                glBindFramebuffer( GL_FRAMEBUFFER, 0 );
                glClearBufferfv( GL_COLOR, 0, &glm::vec4( 0.1f, 0.1f, 0.1f, 1.0f )[0] );
                glClearBufferfi( GL_DEPTH_STENCIL, 0, 1.0f, 0 );
 
                glfwSwapBuffers( pWindow );
                glfwPollEvents();
        }
 
        return EXIT_SUCCESS;
}

Win32/GLEW

[font='Helvetica Neue', Arial, Verdana, sans-serif]#define GLEW_STATIC[/font]
#define WIN32_LEAN_AND_MEAN
 
#include <Windows.h>
#include <GL/glew.h>
#include <GL/wglew.h>
#include <GLM/glm.hpp>
#include "Debugging/glDebugging.h"
 
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
 
struct RunInfo
{
        bool bRunning;
};
 
int main( int argc, char* argv[] )
{
        STARTUPINFO startInfo;
        HINSTANCE hInstance = ( HINSTANCE )GetModuleHandle( NULL );
       
        GetStartupInfo( &startInfo );
 
        WNDCLASSEX wcex;
 
        wcex.cbSize                     = sizeof( WNDCLASSEX );
    wcex.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_APPLICATION ) );
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = ( HBRUSH )( COLOR_WINDOW + 1 );
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = L"NoGLFW";
    wcex.hIconSm        = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_APPLICATION ) );
 
        if( !RegisterClassEx( &wcex ) )
                return -1;
 
        RECT rc = { 0, 0, 640, 360 };
        AdjustWindowRectEx( &rc, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE );
 
        HWND hWnd = CreateWindowEx(
                WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
                L"NoGLFW",
                L"NoGLFW",
                WS_OVERLAPPEDWINDOW,
                0,
                0,
                rc.right - rc.left,
                rc.bottom - rc.top,
                NULL,
                NULL,
                hInstance,
                NULL );
        if( !hWnd )
                return -1;
 
        PIXELFORMATDESCRIPTOR pfd =
        {
                sizeof( PIXELFORMATDESCRIPTOR ),                                                        // Struct size
                1,                                                                                                                      // Version
                PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,     // Support OpenGL/Double Buffering
                PFD_TYPE_RGBA,                                                                                          // Request RGBA format
                32,                                                                                                                     // Output color depth
                0, 0, 0, 0, 0, 0,                                                                                       // Color bits, ignored
                0,                                                                                                                      // No alpha buffer
                0,                                                                                                                      // Shift bit, ignored
                0,                                                                                                                      // No accumulation buffer
                0, 0, 0, 0,                                                                                                     // Accumulation bits, ignored
                0,                                                                                                                      // No z-buffer
                0,                                                                                                                      // No stencil buffer
                0,                                                                                                                      // No auxillary buffer
                PFD_MAIN_PLANE,                                                                                         // Main drawing layer
                0,                                                                                                                      // Reserved
                0, 0, 0                                                                                                         // Layer masks, ignored
        };
 
        HDC hDc = GetDC( hWnd );
        if( !hDc )
                return -1;
 
        unsigned int pixelFormat = ChoosePixelFormat( hDc, &pfd );
        if( !pixelFormat )
                return -1;
 
        if( !SetPixelFormat( hDc, pixelFormat, &pfd ) )
                return -1;
 
        HGLRC tempContext = wglCreateContext( hDc );
        wglMakeCurrent( hDc, tempContext );
 
        glewExperimental = GL_TRUE;
        GLenum err = glewInit();
 
        int attribs[] =
        {
                WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
                WGL_CONTEXT_MINOR_VERSION_ARB, 1,
                WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
                WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
                WGL_CONTEXT_FLAGS_ARB, 0,
                0
        };
 
        HGLRC hRc = tempContext;
        if( wglewIsSupported( "WGL_ARB_create_context" ) == 1 )
        {
                hRc = wglCreateContextAttribsARB( hDc, 0, attribs );
                wglMakeCurrent( NULL, NULL );
                wglDeleteContext( tempContext );
                wglMakeCurrent( hDc, hRc );
        }
 
        //Checking GL version
    const GLubyte* GLVersionString = glGetString( GL_VERSION );
 
    //Or better yet, use the GL3 way to get the version number
    int OpenGLVersion[2];
    glGetIntegerv( GL_MAJOR_VERSION, &OpenGLVersion[0] );
    glGetIntegerv( GL_MINOR_VERSION, &OpenGLVersion[1] );
 
        RunInfo runInfo;
        runInfo.bRunning = true;
 
        SetWindowLongPtr( hWnd, GWLP_USERDATA, ( LONG_PTR )&runInfo );
 
        ShowWindow( hWnd, SW_SHOWDEFAULT );
        UpdateWindow( hWnd );
 
        MSG msg = { 0 };
        while( runInfo.bRunning )
        {
                if( PeekMessage( &msg, hWnd, 0, 0, PM_REMOVE ) )
                {
                        TranslateMessage( &msg );
                        DispatchMessage( &msg );
                }
 
                glViewport( 0, 0, 640, 360 );
                glClearBufferfv( GL_COLOR, 0, &glm::vec4( 0.1f, 0.1f, 0.1f, 1.0f )[0] );
 
                SwapBuffers( hDc );
        }
 
        return 0;
}
 
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
        RunInfo* pRunInfo = ( RunInfo* )GetWindowLongPtr( hWnd, GWLP_USERDATA );
 
        switch( message )
        {
                case WM_DESTROY:
                        {
                                pRunInfo->bRunning = false;
                                PostQuitMessage( 0 );
                        }
                        break;
        }
 
        return DefWindowProc( hWnd, message, wParam, lParam );
}

3DS Max .NET SDK - Scene Exporter

03 November 2012 - 09:06 AM

I have posted this on the Autodesk forums and Google group. Although there is zero activity, so not quite sure where else to go except here.

I'm attempting to write a scene exporter using the 3DS Max .NET SDK. I currently have what I thought was the bare minimum setup in order to create an exporter. After building the DLL I copy it into the bin/assemblies directory and launch MAX 2013 and attempt an export. I receive the message "An error has occurred and the application will now close. No scene changes have occurred since your last save."


I copy and pasted the Descriptor and Loader from the example in http://area.autodesk...rp-source-code.

Do I have something set up wrong in my code that could cause this issue? My project references Autodesk.Max and the "Copy Local" is set to false.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Max;
namespace TestExporter
{
	public class TestExporter : Autodesk.Max.Plugins.SceneExport
	{
		public override string AuthorName
		{
			get { return "Test"; }
		}
		public override string CopyrightMessage
		{
			get { return "Test"; }
		}
		public override int DoExport(string name, Autodesk.Max.IExpInterface ei, Autodesk.Max.IInterface i, bool suppressPrompts, uint options)
		{
			return 1;
		}
		public override string Ext(int n)
		{
			return "mesh";
		}
		public override int ExtCount
		{
			get { return 1; }
		}
		public override string LongDesc
		{
			get { return "Test Export Utility"; }
		}
		public override string OtherMessage1()
		{
			return "";
		}
		public override string OtherMessage2()
		{
			return "";
		}
		public override string ShortDesc
		{
			get { return "Test"; }
		}
		public override void ShowAbout(IntPtr hWnd)
		{
			return;
		}
		public override uint Version
		{
			get { return 1; }
		}
	}
	public class Descriptor : Autodesk.Max.Plugins.ClassDesc2
	{
		public override string Category
		{
			get { return "Test"; }
		}
		public override IClass_ID ClassID
		{
			get { return Loader.Global.Class_ID.Create(0x3990388b, 0x696868d0); }
		}
		public override string ClassName
		{
			get { return "Test Export Utility"; }
		}
		public override object Create(bool loading)
		{
			return new TestExporter();
		}
		public override bool IsPublic
		{
			get { return true; }
		}
		public override SClass_ID SuperClassID
		{
			get { return SClass_ID.SceneExport; }
		}
	}
	public static class Loader
	{
		public static IGlobal Global;
		public static IInterface13 Core;
		public static void AssemblyMain()
		{
			Global = Autodesk.Max.GlobalInterface.Instance;
			Core = Global.COREInterface13;
			Core.AddClass(new Descriptor());
		}
	}
}

DirectX 11 Depth Stencil

25 June 2011 - 03:59 PM

Hi, I was wondering if anyone could help me out with an issue I am having. I know I can bind the depth stencil as a shader resource. Although I'm tripping up on the step where I actually create the shader resource view. Currently I get E_INVAILDARG although I have no idea how to tell what is actually invalid. Is there a way to determine what is invalid other than looking at the HRESULT?

My selection of format types came from a post MJP made in another thread where a similar question was raised: link


I receive on the last line of code below.


HRESULT hr = S_OK;

D3D11_TEXTURE2D_DESC texDesc = 
{
	mWidth,													//width
	mHeight,												//height
	1,														//mip levels
	1,														//array size
	DXGI_FORMAT_R24G8_TYPELESS,								//format,
	{1, 0},													//sample desc(count, quality)
	D3D11_USAGE_DEFAULT,									//usage
	D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE,	//bind flags
	0,														//cpu access flags
	0														//misc flags
};

hr = pDevice->CreateTexture2D(&texDesc, 0, &mpDepthStencilTexture);
if(FAILED(hr))
{
	return hr;
}

D3D11_DEPTH_STENCIL_VIEW_DESC viewDesc = { };
viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
viewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
viewDesc.Texture2D.MipSlice = 0;

hr = pDevice->CreateDepthStencilView(mpDepthStencilTexture, &viewDesc, &mpDepthStencilView);

D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc = { };
viewDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
viewDesc.Texture2D.MipLevels = 0;

hr = pDevice->CreateShaderResourceView(mpDepthStencilTexture, &viewDesc, &mpDepthStencilSRV);


Thank you for your help.

Win32 Window Issue (C++)

02 June 2011 - 11:36 AM

I was wondering if anyone could help me out with a little problem I am having.

I started a new empty Windows C++ project in Visual Studio 2010. I added, what I've known to be, the basic code for getting a window up and running with a simple message loop. Already I am having an unusual issue with my window. When I launch the program my window appears but I always get the busy cursor icon. I have no control over minimizing/maximizing/moving/etc. the window. Has anyone ever seen this happen? I'm on Windows 7 if it makes any difference.

From what I can tell this looks no different than any other Windows program I have written...

One thing I tried was to use the basic Windows C++ project template instead of empty. That seemed to work well. The only thing they seemed to do different is use TranslateAccelerator, which I have never used before, instead of PeekMessage.

#include <Windows.h>

//Forward declarations
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND CreateAndRegisterWindow(const char* name);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
    	HWND hWnd = CreateAndRegisterWindow("Sandbox");
    	if(hWnd == NULL)
    	{
            	MessageBox(NULL, "Error!", "Unable to create and register the Sandbox window", MB_ICONERROR);
            	return -1;
    	}

    	MSG msg = { };
    	while(msg.message != WM_QUIT)
    	{
            	//Process current window messages
            	if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            	{
                    	TranslateMessage(&msg);
                    	DispatchMessage(&msg);
            	}
            	else
            	{
            	}
    	}

    	return static_cast<int>(msg.wParam);
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    	switch(uMsg)
    	{
    	case WM_DESTROY:
            	{
                    	PostQuitMessage(0);
            	}
            	return 0;

    	case WM_PAINT:
            	{
                    	PAINTSTRUCT ps;
                    	HDC hdc = BeginPaint(hWnd, &ps);

                    	FillRect(hdc, &ps.rcPaint, reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1));
                    	EndPaint(hWnd, &ps);
            	}
            	return 0;
    	}

    	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

HWND CreateAndRegisterWindow(const char* name)
{
    	//Register the window class.
    	WNDCLASS wc = { };
    	wc.lpfnWndProc = WindowProc;
    	wc.lpszClassName = name;

    	RegisterClass(&wc);

    	//Create the window
    	HWND hWnd = CreateWindowEx(
            	0,
            	name,
            	name,
            	WS_OVERLAPPEDWINDOW,
            	CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
            	NULL,
            	NULL,
            	NULL,
            	NULL);

    	if(hWnd == NULL)
    	{
            	return NULL;
    	}

    	ShowWindow(hWnd, SW_SHOWDEFAULT);
    	return hWnd;
}

Issue with Boost property_tree

06 February 2011 - 02:41 PM

I'm playing around with using Boost property_tree and I'm not able to use the read_xml function it seems. Not sure exactly what the issue is and I followed the exact code in the "Five Minute Tutorial" for the property_tree on the Boost site. I'm pretty weak with templates especially debugging issues related to them, assuming that is what the problem is.

Not sure if it matters but I am using Boost 1.43 and Visual Studio 2010.


My code:
	#include "myInclude.h"					//Includes string
	#include <boost\property_tree\ptree.hpp>    
	#include <boost\property_tree\xml_parser.hpp>


	int LoadConfiguration(const std::string &configFile)
	{
		using boost::property_tree::ptree;
		ptree pt;

		boost::property_tree::read_xml(configFile, pt);
	}


Error:
 1>c:\development\boost\boost_1_43\boost\property_tree\detail\ptree_implementation.hpp(30): error C2440: 'specialization' : cannot convert from 'const std::string std::_Pair_base<_Ty1,_Ty2>::* ' to 'const std::basic_string<_Elem,_Traits,_Ax> std::pair<_Ty1,_Ty2>::* '
1>          with
1>          [
1>              _Ty1=const std::string,
1>              _Ty2=boost::property_tree::basic_ptree<std::string,std::string>
1>          ]
1>          and
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ax=std::allocator<char>,
1>              _Ty1=const std::string,
1>              _Ty2=boost::property_tree::basic_ptree<std::string,std::string>
1>          ]
1>          Standard conversion from pointer-to-member of base to pointer-to-member of derived is not applied for template arguments
1>          c:\development\boost\boost_1_43\boost\property_tree\detail\ptree_implementation.hpp(159) : see reference to class template instantiation 'boost::property_tree::basic_ptree<Key,Data>::subs' being compiled
1>          with
1>          [
1>              Key=std::string,
1>              Data=std::string
1>          ]
1>          c:\development\boost\boost_1_43\boost\property_tree\detail\ptree_implementation.hpp(159) : while compiling class template member function 'boost::property_tree::basic_ptree<Key,Data>::basic_ptree(void)'
1>          with
1>          [
1>              Key=std::string,
1>              Data=std::string
1>          ]
1>          d:\projects\marabunta\marabunta\marabunta.cpp(31) : see reference to class template instantiation 'boost::property_tree::basic_ptree<Key,Data>' being compiled
1>          with
1>          [
1>              Key=std::string,
1>              Data=std::string
1>          ]
1>

PARTNERS