Jump to content

  • Log In with Google      Sign In   
  • Create Account

Erik Rufelt

Member Since 17 Apr 2002
Offline Last Active Jun 15 2016 08:30 AM

#5286608 Window Creation in Win 7

Posted by Erik Rufelt on 13 April 2016 - 02:05 AM

You don't seem to be linking to or initializing GLEW.

Read this page: https://www.opengl.org/wiki/OpenGL_Loading_Library

 

As well as this one: http://glew.sourceforge.net/basic.html




#5285834 X11 + OpenGL causes segfault

Posted by Erik Rufelt on 08 April 2016 - 10:41 AM

glXMakeCurrent also has a return-code, like the single one you don't check.. :)

Probably the context isn't properly made current there.

If it is, try getting the function pointers for the normal GL functions instead of relying on them by linking.




#5283671 heightmap sample in vertex shader

Posted by Erik Rufelt on 27 March 2016 - 12:06 AM

Sounds like your texture isn't correctly loaded or bound, and your SampleLevel always returns 0.

0 is the default that will be returned if no texture is available to read from.

If you run your game from Visual Studio with the debugger and create your device with D3D11_CREATE_DEVICE_DEBUG you should get debug output in the Output window in Visual Studio if that is the case.




#5277254 Correct way of doing Mouse Picking

Posted by Erik Rufelt on 21 February 2016 - 03:25 AM

One thing that looks like a mistake is this:

"-(2 * mouse.Y) / viewport.Height -1"

 

Should be +1 at the end, or your values will be between -3 and -1 instead of -1 and 1.




#5277233 Interstellar trade at a relativistic timescale?

Posted by Erik Rufelt on 20 February 2016 - 11:45 PM

Very interesting scenario, though I find it difficult to think of a realistic setup at all without more information. How big is the colony?

 

If it's something of an off-shore platform out there, that would likely make the colony rather small, and I would expect the crew on the spaceships to also rotate the crew on the colony.

So basically the decision to go work on the colony is a 10-20 year contract in "your time", but a ~ 30-40 year contract in "real time".

 

If it's a major settlement, I would expect their primary objective is to establish self-sufficiency, and after the first century or so these trade missions will probably mostly be about luxury items or scientific exchange that would impact production on the colony during the decade after the ship arrives. (Depending on whether several ships arrive during the 24 years, or if there is just one or a few ships that go back and fourth).

 

There is also the question of political stability in the solar system. Are there still economic problems?

I suspect some competition for a chance to jump 24 years into the future whenever there's some form of unrest. If scientific achievements are still happening at the rate they are now, this would likely be extremely appealing even in good conditions for a lot of people, especially if they could go with their families.




#5277182 Vulkan is Next-Gen OpenGL

Posted by Erik Rufelt on 20 February 2016 - 12:42 PM

I think those semaphores are just copied from the multi-threaded multi-queue example, and aren't actually required when acquiring the image and presenting on the same thread and/or the same queue, even without any Wait, if I understand things correctly.

 

AcquireImage is supposed to block until an image is available or return an error or timeout, and present is supposed to be added to the end of the queue. Queues must be externally synchronized, so the only reason to use a semaphore on AcquireImage is if another thread is about to start submitting command buffers for drawing to the image before AcquireImage returns. (This also makes AcquireImage returning the index of the next buffer redundant, as it must already be known if another thread is already building the command buffer for the frame using that image before it is returned as available).

 

The semaphore on Present makes sense if the present is submitted to a different queue than is drawing the graphics, even in single-threaded apps, as the last actual drawing command must finish executing on its queue before the image is presented on the other queue, but if submitting the Present on the same queue it is redundant, threaded or not (though threading on one queue might not make much sense.. unless submitting a present to the queue is actually expected to be a slow operation and the main thread wants to start processing the next frame or something without using the queue).




#5277129 Vulkan is Next-Gen OpenGL

Posted by Erik Rufelt on 20 February 2016 - 04:10 AM

Did anyone create anything with it yet?

 

I tried it out and it works reasonably well, though feels beta. VSync in particular doesn't work at all when I use the SDK, but if I load the functions from the Nvidia driver directly I can't turn it off (no immediate mode reported and ignored if used anyway). Haven't been able to find how they manage to turn it off from the SDK sources... smile.png

Also the SDK crashes whenever I enable the debug validation.. though if I enable the individual layers but leave out the threading validation layer it seems to work and I get debug output.

 

Haven't found anything about fullscreen mode. I'm reasonably sure when I first tried a fullscreen top-level window I saw a distinct automatic modeswitch like OpenGL does.. but today it stays in "fullscreen windowed".

Only B8G8R8A8 modes reported for me.. no 30-bit backbuffers in the current Nvidia driver apparently.

 

Documentation feels somewhat lacking. In particular the swap chain parts, where the various examples do things different ways and none quite make sense. When I do get VSync the blocking seems to be in QueuePresent.. whereas I would expect it to just queue up the present and the wait to be in AcquireImage. Perhaps we're supposed to always present on a separate thread or something... I get the delay in present even if I wait for the queue and device to become idle before I call it so it definitely seems to be a wait for the actual VBlank. EDIT: Actually not entirely sure on that, not used enough to this yet to be sure I do things the right way.

 

Debug validation seems to work, apart from the crash and again problems with the swap-chain. Docs specifically says I need to transition the image between present mode and color attachment, but ignoring that and transitioning it to whatever insane layout I choose at random doesn't give any warnings and works happily.

 

 

Didn't get far past the setup yet so everything else may still be great smile.png




#5274454 Vulkan is Next-Gen OpenGL

Posted by Erik Rufelt on 05 February 2016 - 09:07 AM


Also another link for another calendar door. biggrin.png
http://www.phoronix.com/scan.php?page=news_item&px=Vulkan-Programming-Guide-Pre

 

They could've upgraded the cover image model to say Vulkan and not OpenGL..




#5274178 Window Creation in Win 7

Posted by Erik Rufelt on 03 February 2016 - 11:47 PM

You need to set the window pixel format and then create an OpenGL context.

You should be able to pick out the parts required to get it running in your window from this example:

#include <windows.h>
#include <gl/gl.h>

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

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

// Main
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	// Window class
	WNDCLASSEX wc = {};
	wc.cbSize = sizeof(wc);
	wc.lpszClassName = TEXT("MyClass");
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.style = CS_OWNDC;
	RegisterClassEx(&wc);

	// Window
	HWND hWnd = CreateWindowEx(
		0,
		wc.lpszClassName,
		TEXT("OpenGL Window"),
		WS_OVERLAPPEDWINDOW |
			WS_CLIPSIBLINGS |
			WS_CLIPCHILDREN,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		NULL,
		NULL,
		hInstance,
		NULL
	);

	// Get DC
	HDC hDC = GetDC(hWnd);

	// Pixel format
	PIXELFORMATDESCRIPTOR pfd = {};
	pfd.nSize = sizeof(pfd);
	pfd.nVersion = 1;
	pfd.dwFlags =
		PFD_DRAW_TO_WINDOW |
		PFD_SUPPORT_OPENGL |
		PFD_DOUBLEBUFFER |
		PFD_SUPPORT_COMPOSITION;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;

	int pf = ChoosePixelFormat(hDC, &pfd);
	SetPixelFormat(hDC, pf, &pfd);

	// OpenGL context
	HGLRC hGLRC = wglCreateContext(hDC);

	wglMakeCurrent(hDC, hGLRC);

	// Get OpenGL version and set it as window title
	SetWindowTextA(hWnd, (char*)glGetString(GL_VERSION));

	// Main loop
	ShowWindow(hWnd, nCmdShow);
	while(true) {
		MSG msg;
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0) {
			if(msg.message == WM_QUIT)
				break;
			else {
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else {
			// Draw
			glClearColor(1.0f, 0.7f, 0.2f, 1.0f);
			glClear(GL_COLOR_BUFFER_BIT);

			SwapBuffers(hDC);
		}
	}

	// Clean up
	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(hGLRC);

	UnregisterClass(wc.lpszClassName, hInstance);

	return 0;
}

// Window proc
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch(msg) {
		case WM_DESTROY:
			PostQuitMessage(0);
		return 0;

		case WM_SIZE:
			// Resize GL rendering area to match window size
			glViewport(0, 0, LOWORD(lParam), HIWORD(lParam));
		return 0;
	}

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

However, that will only really allow you to use quite old OpenGL functionality without some extra work, as the newer version functions aren't readily available in opengl32.lib. The default library only provides version 1.1 or something like that (even when the context version is 4.5).

 

To load more functions you need to request their function pointers from WGL while your GL context is current, for example to use the glCompileShader function:

PFNGLCOMPILESHADERPROC glCompileShader = (PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader");

The function pointer will match a function in the NVidia or AMD driver for example, not in the system OpenGL DLL.

 

This is a bit tedious, and if you want to do it manually the best way is probably to download glcorearb.h from opengl.org and write a script that goes through it and loads all the functions into some appropriate wrapper or global pointers or something.

There are libraries written specifically to take care of all this, such as GLEW for example: http://glew.sourceforge.net/

It can take care of checking all extensions etc. for you and help make sure everything is loaded properly and detect when it isn't. This is especially useful when loading extensions that may be available only on some drivers. If you make sure the context version is 4.x and you load only core functionality matching that version it's just about loading all the function pointers.




#5274108 Multiplication and division of four chars packed in one int

Posted by Erik Rufelt on 03 February 2016 - 02:01 PM

What OS is it for?

On Android there's Renderscript that is specifically made for things like image filters that might work. In general you should be able to do a lot of stuff in GLSL shaders. I would investigate that possibility as it could save you a lot of work and improve performance.




#5272824 CreateSwapChain "fullscreen" random fail with DXGI_STATUS_OCCLUDED

Posted by Erik Rufelt on 27 January 2016 - 06:23 AM

Try creating the swap chain in windowed mode and going to fullscreen with SetFullscreenState.




#5272589 Vulkan is Next-Gen OpenGL

Posted by Erik Rufelt on 25 January 2016 - 11:15 AM

Based on Khronos' previous performance I'd say that they're perfectly capable of going from information blackout to full release overnight.

 

They're also quite capable of scrapping Vulkan and releasing an OpenGL 5.0 that is little more than new extensions layered on the existing mess, even at this late stage.

 

The estimated release is alarmingly close to April 1 ...




#5272553 WinAPI WNDPROC to Engine/Game MessageHandler

Posted by Erik Rufelt on 25 January 2016 - 01:26 AM

What do you feel isn't elegant about it?

Another way is to capture messages in the main loop when returned from GetMessage/PeekMessage.

 

One thing I see is that you should probably not always return DefWindowProc at the end, but let 'MessageHandler' decide. Though I'm not entirely clear on what your message handler does, do you pass everything to it or where do you decide what "converted winapi parameters" are?




#5270774 Draw dashed stroke around rectangle/ellipse with single draw call

Posted by Erik Rufelt on 12 January 2016 - 04:51 PM

There is a strip restart index that starts a new strip on the next index. Check the bottom of this page: https://msdn.microsoft.com/en-us/library/windows/desktop/bb205124%28v=vs.85%29.aspx




#5270765 Enable Z buffer only for ALPHA CHANNEL > 0

Posted by Erik Rufelt on 12 January 2016 - 04:16 PM

The code you posted shows no alpha testing (D3DRS_ALPHATESTENABLE), are you sure you're using that one?






PARTNERS