Exemplo n.º 1
0
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const EGLint* attribList, const GLUSboolean fullscreen)
{
	EGLConfig eglConfig;

	EGLint eglNativeVisualID;

	EGLNativeWindowType eglNativeWindowType;

	if (g_windowCreated)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Window already exists");

		return GLUS_FALSE;
	}

	if (!glusEGLCreateContext(_glusGetNativeDisplayType(), &g_eglDisplay, &eglConfig, &g_eglContext, attribList, g_eglContextClientVersion))
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could preinitialize EGL");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	if (!glusEGLGetNativeVisualID(g_eglDisplay, eglConfig, &eglNativeVisualID))
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not get native visual ID");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	eglNativeWindowType = _glusCreateNativeWindowType(title, width, height, fullscreen, g_noResize, eglNativeVisualID);

	if (!eglNativeWindowType)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not create native window");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	if (!glusEGLCreateWindowSurfaceMakeCurrent(eglNativeWindowType, &g_eglDisplay, &eglConfig, &g_eglContext, &g_eglSurface))
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not post initialize EGL");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	_glusGetWindowSize(&g_width, &g_height);

	g_windowCreated = GLUS_TRUE;

	return GLUS_TRUE; // Success
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
	glusInitFunc(init);
	glusPrepareContext(3, 2, GLUS_FORWARD_COMPATIBLE_BIT);

	if (!glusCreateWindow("C++ OpenGL Append With Transform Feedback", 640, 480, GLUS_FALSE))
	{
		printf("Could not create window!");
		return -1;
	}

	// Init GLEW
	glewExperimental = GL_TRUE;
  GLenum err=glewInit();
  if(err!=GLEW_OK)
  {
    sprintf("glewInitError", "Error: %s\n", glewGetErrorString(err));
    return -1;
  }
  glGetError(); // flush error state variable, caused by glew errors
  
	if (!glewIsSupported("GL_VERSION_3_2"))
	{
		printf("OpenGL 3.2 not supported.");

		glusDestroyWindow();
		return -1;
	}

	glusRun();

	return 0;
}
Exemplo n.º 3
0
/**
 * Main entry point.
 */
int main(int argc, char* argv[])
{
	glusInitFunc(init);

	glusReshapeFunc(reshape);

	glusUpdateFunc(update);

	glusTerminateFunc(terminate);

	glusPrepareContext(3, 3, GLUS_FORWARD_COMPATIBLE_BIT);

	if (!glusCreateWindow("GLUS Example Window", 640, 480, GLUS_FALSE))
	{
		printf("Could not create window!");
		return -1;
	}

	// Init GLEW
	glewExperimental = GL_TRUE;
	glewInit();

	// Only continue, if OpenGL 3.3 is supported.
	if (!glewIsSupported("GL_VERSION_3_3"))
	{
		printf("OpenGL 3.3 not supported.");

		glusDestroyWindow();
		return -1;
	}

	glusRun();

	return 0;
}
Exemplo n.º 4
0
GLUSboolean GLUSAPIENTRY glusRun(GLUSvoid)
{
	// Init Engine
	if (glusInit)
	{
		if (!glusInit())
		{
			glusDestroyWindow(); // Destroy The Window

			return GLUS_FALSE; // Exit The Program
		}
	}

	g_initdone = GLUS_TRUE;

	// Do the first reshape
	if (glusReshape)
	{
		glusReshape(g_width, g_height);
	}

	while (!g_done) // Loop That Runs While done=FALSE
	{
		if (glusUpdate)
		{
			g_done = !glusUpdate(glusGetElapsedTime());
		}

		eglSwapBuffers(g_eglDisplay, g_eglSurface); // Swap Buffers (Double Buffering)

		_glusPollEvents();
	}

	// Terminate Game
	if (glusTerminate)
	{
		glusTerminate();
	}

	// Shutdown
	glusDestroyWindow(); // Destroy The Window

	return GLUS_TRUE; // Exit The Program
}
Exemplo n.º 5
0
GLUSvoid GLUSAPIENTRY glusShutdown(GLUSvoid)
{
	// Terminate Game
	if (glusTerminate)
	{
		glusTerminate();
	}

	// Shutdown
	glusDestroyWindow(); // Destroy The Window
}
Exemplo n.º 6
0
/**
 * Main entry point.
 */
int main(int argc, char* argv[])
{
	glusInitFunc(init);
	glusReshapeFunc(reshape);
	glusUpdateFunc(update);
	glusTerminateFunc(shutdown);
  glusMouseFunc(mouse);
  glusMouseMoveFunc(mouseMove);
  glusKeyFunc(keyboard);

	glusPrepareContext(3, 0, GLUS_FORWARD_COMPATIBLE_BIT);

	if (!glusCreateWindow("C++, GLSL Ray Marching sample", 640, 480, GLUS_FALSE))
	{
		printf("Could not create window!");
		return -1;
	}

	// Init GLEW
	glewExperimental = GL_TRUE;
  GLenum err=glewInit();
  if(err!=GLEW_OK)
  {
    sprintf("glewInitError", "Error: %s\n", glewGetErrorString(err));
    return -1;
  }
  glGetError(); // flush error state variable, caused by glew errors
  

	// Only continue, if OpenGL 3.3 is supported.
	if (!glewIsSupported("GL_VERSION_3_0"))
	{
		printf("OpenGL 3.0 not supported.");

		glusDestroyWindow();
		return -1;
	}

	glusRun();

	return 0;
}
Exemplo n.º 7
0
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const GLUSint depthBits, const GLUSint stencilBits, const GLUSboolean fullscreen)
{
	GLUSenum err;

	if (g_window)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Window already exists");

		return GLUS_FALSE;
	}

	if (!glfwInit())
	{
		glusLogPrint(GLUS_LOG_ERROR, "GLFW could not be initialized");

		return GLUS_FALSE;
	}

	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, g_major);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, g_minor);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, g_flags & GLUS_FORWARD_COMPATIBLE_BIT);
	glfwWindowHint(GLFW_OPENGL_PROFILE, (g_flags & GLUS_FORWARD_COMPATIBLE_BIT) ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
	glfwWindowHint(GLFW_SAMPLES, g_numberSamples);
	glfwWindowHint(GLFW_RESIZABLE, !g_noResize);
	glfwWindowHint(GLFW_DEPTH_BITS, depthBits);
	glfwWindowHint(GLFW_STENCIL_BITS, stencilBits);
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, g_debug || (g_flags & GLUS_DEBUG_CONTEXT_BIT));

	g_window = glfwCreateWindow(width, height, title, fullscreen ? glfwGetPrimaryMonitor() : 0, 0);
	if (!g_window)
	{
		glfwTerminate();

		glusLogPrint(GLUS_LOG_ERROR, "GLFW window could not be opened");

		return GLUS_FALSE;
	}

	glfwMakeContextCurrent(g_window);

	glewExperimental = GLUS_TRUE;

	err = glewInit();

	if (GLUS_OK != err)
	{
		glusDestroyWindow();

		glusLogPrint(GLUS_LOG_ERROR, "GLEW could not be initialized: %x", err);

		return GLUS_FALSE;
	}

	// Catch all OpenGL errors so far.
	glGetError();

	if (!glusIsSupported(g_major, g_minor))
	{
		glusDestroyWindow();

		glusLogPrint(GLUS_LOG_ERROR, "OpenGL %u.%u not supported", g_major, g_minor);

		return GLUS_FALSE;
	}

	glfwSetWindowSizeCallback(g_window, glusInternalReshape);
	glfwSetWindowCloseCallback(g_window, glusInternalClose);
	glfwSetKeyCallback(g_window, glusInternalKey);
	glfwSetMouseButtonCallback(g_window, glusInternalMouse);
	glfwSetScrollCallback(g_window, glusInternalMouseWheel);
	glfwSetCursorPosCallback(g_window, glusInternalMouseMove);

	glfwGetWindowSize(g_window, &g_width, &g_height);

	if (g_debug && glusIsSupported(4, 3))
	{
		glusLogSetLevel(GLUS_LOG_DEBUG);

		glDebugMessageCallback(&glusInternalDebugMessage, 0);
	}

	return GLUS_TRUE; // Success
}
Exemplo n.º 8
0
GLUSboolean GLUSAPIENTRY glusRun(GLUSvoid)
{
	MSG		msg;									// Windows Message Structure

	GLUSboolean done = GLUS_FALSE;						// Bool Variable To Exit Loop

	// Init Engine
	if (glusInit)
	{
		if (!glusInit())
		{
			glusDestroyWindow();						// Destroy The Window

			return GLUS_FALSE;							// Exit The Program
		}
	}

	g_initdone = GLUS_TRUE;

	// Do the first reshape
	if (glusReshape)
	{
		glusReshape(g_width, g_height);
	}

	while(!done)									// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done = GLUS_TRUE;					// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key
			if (g_active)							// Program Active?
			{
				if (glusUpdate)
				{
					done = !glusUpdate(glusGetElapsedTime());
				}

				if (!done)
				{
					SwapBuffers(g_hDC);				// Swap Buffers (Double Buffering)
				}
			}
		}
	}

	// Terminate Game
	if (glusTerminate)
	{
		glusTerminate();
	}

	// Shutdown
	glusDestroyWindow();							// Destroy The Window

	return GLUS_TRUE;								// Exit The Program
}
Exemplo n.º 9
0
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, GLUSuint width, GLUSuint height, GLUSboolean fullscreen)
{
	GLUSint attribList[] =
	{
	  WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
      WGL_CONTEXT_MINOR_VERSION_ARB, 0,
      WGL_CONTEXT_FLAGS_ARB, 0,
      0
	};

	static PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		32,											// Select Our 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
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};

	GLUSuint	PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	g_fullscreen=fullscreen;			// Set The Global Fullscreen Flag

	g_hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= g_hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "GLUS";								// Set The Class Name

	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		return GLUS_FALSE;											// Return FALSE
	}
	
	if (fullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= 32;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		{
			glusDestroyWindow();
			return GLUS_FALSE;
		}
	}

	if (fullscreen)
	{
		dwExStyle = WS_EX_APPWINDOW;							// Window Extended Style
		dwStyle = WS_POPUP;										// Windows Style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle = WS_OVERLAPPEDWINDOW;							// Windows Style
	}

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size

	// Create The Window
	if (!(g_hWnd = CreateWindowEx(dwExStyle,						// Extended Style For The Window
								"GLUS",								// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								g_hInstance,						// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		glusDestroyWindow();
		return GLUS_FALSE;
	}
	
	if (!(g_hDC = GetDC(g_hWnd)))					// Did We Get A Device Context?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if (!(PixelFormat = ChoosePixelFormat(g_hDC, &pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if(!SetPixelFormat(g_hDC, PixelFormat, &pfd))	// Are We Able To Set The Pixel Format?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if (!(g_hRC=wglCreateContext(g_hDC)))			// Are We Able To Get A Rendering Context?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if(!wglMakeCurrent(g_hDC, g_hRC))				// Try To Activate The Rendering Context
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if (g_major >= 3)
	{
		PFNWGLCREATECONTEXTATTRIBSARBPROCTEMP wglCreateContextAttribsARBTemp = NULL;
		HGLRC hRCTemp = NULL;

		GLUSint attribList[] =
		{
		  WGL_CONTEXT_MAJOR_VERSION_ARB, 1,
		  WGL_CONTEXT_MINOR_VERSION_ARB, 0,
      WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | WGL_CONTEXT_DEBUG_BIT_ARB,        
      0, 0,
      0
		};

		attribList[1] = g_major;
		attribList[3] = g_minor;
		//attribList[5] = g_flags;

		if (!(wglCreateContextAttribsARBTemp = (PFNWGLCREATECONTEXTATTRIBSARBPROCTEMP)wglGetProcAddress("wglCreateContextAttribsARB")))
		{
			glusDestroyWindow();
			return GLUS_FALSE;							// Return FALSE
		}

		if (!(hRCTemp = wglCreateContextAttribsARBTemp(g_hDC, 0, attribList)))
		{
			glusDestroyWindow();
			return GLUS_FALSE;							// Return FALSE
		}

		if(!wglMakeCurrent(NULL, NULL))
		{
			wglDeleteContext(hRCTemp);

			glusDestroyWindow();
			return GLUS_FALSE;							// Return FALSE
		}

		if (!wglDeleteContext(g_hRC))
		{
			wglDeleteContext(hRCTemp);

			glusDestroyWindow();
			return GLUS_FALSE;							// Return FALSE
		}

		g_hRC = hRCTemp;

		if(!wglMakeCurrent(g_hDC, g_hRC))
		{
			glusDestroyWindow();
			return GLUS_FALSE;							// Return FALSE
		}
	}

	ShowWindow(g_hWnd, SW_SHOW);					// Show The Window
	SetForegroundWindow(g_hWnd);					// Slightly Higher Priority
	SetFocus(g_hWnd);								// Sets Keyboard Focus To The Window

	g_width = width;
	g_height = height;

	return GLUS_TRUE;								// Success
}
Exemplo n.º 10
0
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const GLUSint depthBits, const GLUSint stencilBits, const GLUSboolean fullscreen)
{
    GLUSenum err;

	if (g_windowCreated)
	{
    	glusLogPrint(GLUS_LOG_ERROR, "Window already exists");

        return GLUS_FALSE;
	}

    if (!glfwInit())
    {
    	glusLogPrint(GLUS_LOG_ERROR, "GLFW could not be initialized");

        return GLUS_FALSE;
    }

    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, g_major);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, g_minor);
    glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, g_flags & GLUS_FORWARD_COMPATIBLE_BIT);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, (g_flags & GLUS_FORWARD_COMPATIBLE_BIT) ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, g_numberSamples);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, g_noResize);

    // If we do not call this function in advance, glfwOpenWindow crashes in Debug under Windows
    glfwSetWindowTitle("");
    if (!glfwOpenWindow(width, height, 8, 8, 8, 8, depthBits, stencilBits, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW))
    {
    	glfwTerminate();

    	glusLogPrint(GLUS_LOG_ERROR, "GLFW window could not be opened");

        return GLUS_FALSE;
    }
    glfwSetWindowTitle(title);

    glewExperimental = GLUS_TRUE;

    err = glewInit();

    if (GLUS_OK != err)
    {
        glusDestroyWindow();

    	glusLogPrint(GLUS_LOG_ERROR, "GLEW could not be initialized: %x", err);

        return GLUS_FALSE;
    }

    if (!glusIsSupported(g_major, g_minor))
    {
        glusDestroyWindow();

        glusLogPrint(GLUS_LOG_ERROR, "OpenGL %u.%u not supported", g_major, g_minor);

        return GLUS_FALSE;
    }

    glfwSetWindowSizeCallback(glusInternalReshape);
    glfwSetWindowCloseCallback(glusInternalClose);
    glfwSetKeyCallback(glusInternalKey);
    glfwSetMouseButtonCallback(glusInternalMouse);
    glfwSetMouseWheelCallback(glusInternalMouseWheel);
    glfwSetMousePosCallback(glusInternalMouseMove);

    glfwGetWindowSize(&g_width, &g_height);

    g_windowCreated = GLUS_TRUE;

    return GLUS_TRUE; // Success
}