bool QShivaContext::makeCurrent(ShivaVGWindowSurfacePrivate *surface)
{
    if (currentSurface)
        currentSurface->isCurrent = false;
    surface->isCurrent = true;
    currentSurface = surface;
    currentSize = surface->size;
#if defined(Q_WS_X11)
    glXMakeCurrent(X11->display, surface->drawable, surface->context);
#endif
    if (!initialized) {
        if (!vgCreateContextSH(currentSize.width(), currentSize.height())) {
            qWarning("vgCreateContextSH(%d, %d): could not create context", currentSize.width(), currentSize.height());
            return false;
        }
        initialized = true;
    } else {
        vgResizeSurfaceSH(currentSize.width(), currentSize.height());
    }
#if defined(QVG_USE_FBO)
    if (surface->fbo)
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, surface->fbo);
    else
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
#endif
    return true;
}
Esempio n. 2
0
	//// C function:: VGboolean vgCreateContextSH(VGint width, VGint height);
	JNIEXPORT jboolean JNICALL  
	Java_com_example_startvg_VG11_vgCreateContextSH(
		JNIEnv * env, jobject obj, 
	  jint width, jint height ){
	    
			nativeClassInit(env);

	    return (jboolean) vgCreateContextSH(
			(VGint) width, 
			(VGint) height
			);
		  // LOGD("vgCreateContextSH -- done. -- width=[%d], height=[%d]", width, height);
		  // return SUCCESS;
  }
Esempio n. 3
0
void testInit(int argc, char **argv,
              int w, int h, const char *title)
{
  int i;
  glutInit(&argc, argv);
  
  #if defined(__APPLE__) || defined(WIN32)
  /*glutInitDisplayString("rgba alpha double stencil samples=4");*/
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA |
                      GLUT_STENCIL | GLUT_MULTISAMPLE);
  #else
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA |
                      GLUT_STENCIL | GLUT_MULTISAMPLE);
  #endif
  
  glutInitWindowPosition(0,0);
  glutInitWindowSize(w,h);
  glutCreateWindow(title);
  
  glutReshapeFunc(testReshape);
  glutDisplayFunc(testDisplay);
  glutIdleFunc(testAnimate);
  glutKeyboardFunc(testKeyboard);
  glutSpecialFunc(testSpecialKeyboard);
  glutMouseFunc(testButton);
  glutMotionFunc(testDrag);
  glutPassiveMotionFunc(testMove);
  atexit(testCleanup);
  
  vgCreateContextSH(w,h);
  
  testW = w;
  testH = h;
  
  for (i=0; i<TEST_CALLBACK_COUNT; ++i)
    callbacks[i] = NULL;
}
Esempio n. 4
0
void ovg_open(int x, int y, int w, int h) {
	Window root;
	XSetWindowAttributes swa,xattr;
	XWindowAttributes gwa;
	XClassHint *classHint;
	XVisualInfo *vi;
	GLint att[] = {
		GLX_RGBA,
		GLX_DEPTH_SIZE, 24,
		GLX_DOUBLEBUFFER, None 
	};

	char instance[] = "libovg",
		 className[] = "libovg";

	if (x_display == NULL){
		//in the case of closing a previous window
		if ((x_display = XOpenDisplay(NULL)) == NULL){
			fprintf(stderr, "Error opening X Display\n");
			return;
		}
	}

	root = DefaultRootWindow(x_display);
	if ((vi = glXChooseVisual(x_display, 0, att)) == NULL){
		fprintf(stderr, "No visual found\n");
		return;
	}

	if (y == 0){
		//for some reason,
		//y=0 makes the window
		//default to center of displau, not 0,0
		y++;
	}

	swa.event_mask = ExposureMask | KeyPressMask;
	win = XCreateWindow(x_display,root,
	                    x,y,w,h,0,
	                    CopyFromParent,InputOutput,
	                    CopyFromParent, CWEventMask,
	                    &swa);

	xattr.override_redirect=0;
	XChangeWindowAttributes(x_display, win, CWOverrideRedirect, &xattr);

	XStoreName(x_display, win, "LibOVG");

	classHint = XAllocClassHint();
	if (classHint){
		classHint->res_name = instance;
		classHint->res_class = className;
	}
	XSetClassHint(x_display, win, classHint);
	XFree(classHint);

	XMapWindow(x_display, win);

	glc = glXCreateContext(x_display, vi, NULL, GL_TRUE);
	glXMakeCurrent(x_display, win, glc);

	// set up screen ratio
	XGetWindowAttributes(x_display, win, &gwa);

 	if (vgCreateContextSH(w, h) != VG_TRUE){
    	fprintf(stderr, "Error creating context\n");
    	return;
    }


    ovg_clear();
}
Esempio n. 5
0
int main() {
	int running = GL_TRUE;
	int width = 640;
	int height = 480;
	int x = 50;
	int y = 50;
	int w = 10;
	int h = 10;
	/*
	Window *win = check_malloc (sizeof(Window));
	win->width = 640;
	win->height = 480;
	*/

	// Initialize GLFW, create a ShivaVG context, open a window

	if( !glfwInit() )
	{
		return 1; // Couldn't initialize GLFW
	}

	int n = glfwOpenWindow(width, height, 0,0,0,0,0,0, GLFW_WINDOW);
	if (!n) {
		glfwTerminate(); // Cleanup GLFW
		return 1; // Couldn't create a window
	}

	glfwSetWindowCloseCallback(window_close_callback);

	glfwSetWindowTitle("Shiva test");

	vgCreateContextSH(width, height); // XXX: TODO: handle errors!!!!
	
	/*
	Rect *r = make_rect(0,0,100,100,0,1,1,1);
	win->rect = r;
	*/
	
	//make color
	VGPaint paint;
	VGfloat paint_array[] = {1,0,1,1};
	paint = vgCreatePaint();
    vgSetParameterfv(paint, VG_PAINT_COLOR, 4, paint_array);
	
	//make rect

	VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
								1,0,0,0, VG_PATH_CAPABILITY_ALL);
	vguRect(path, 0, 0, w, h);


	VGfloat magenta[] = {0.9,0,0,1};
	

	while (running) {
			
		vgSetfv(VG_CLEAR_COLOR, 4, magenta);
		vgClear(0, 0, width, height);
		
		vgLoadIdentity();

		vgTranslate(x, y);
		vgSetPaint(paint, VG_FILL_PATH);
		vgDrawPath(path, VG_FILL_PATH);

		glfwSwapBuffers();	

		// Terminate when ESC is pressed or the window is closed
		running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
	}

	// Close the window, clean up the ShivaVG context, and clean up GLFW
	vgDestroyContextSH();

	// Close window and terminate GLFW
	glfwTerminate();

	
	return 0;
}
Esempio n. 6
0
		void init()
		{
			input_handler = 0;
			init_keytable();

			//_ui_events.reserve(40);

			_ui_key = 0;

			WNDCLASS wc = { 0 };
			wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
			wc.lpfnWndProc = wnd_proc;
			wc.hInstance = GetModuleHandle(0);
			wc.hIcon = LoadIcon(0, IDI_WINLOGO);
			wc.hCursor = LoadCursor(0, IDC_ARROW);
			wc.lpszClassName = "shiva_wc";

			if (!RegisterClass(&wc)) {
				TRACE("Failed to register window class\n");
				return;
			}

			init_gl();

			DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
			DWORD xstyle = WS_EX_APPWINDOW;

			PIXELFORMATDESCRIPTOR pfd = {
				sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
				PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0
			};



			if (0/*fulscreen*/) {
				style = WS_POPUP | WS_MAXIMIZE;
				xstyle |= WS_EX_TOPMOST;

				DEVMODE deviceMode = { 0 };
				deviceMode.dmSize = sizeof(DEVMODE);
				EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &deviceMode);

				if (ChangeDisplaySettings(&deviceMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
					TRACE("Failed to set fullscreen window");
				}
			}

			RECT wr = { 0, 0, 800, 600 };
			AdjustWindowRectEx(&wr, style, 0, xstyle);
			int w = wr.right - wr.left;
			int h = wr.bottom - wr.top;

			wnd = CreateWindowEx(xstyle, wc.lpszClassName, "OpenVG", style, 10, 10, w, h, 0, 0, wc.hInstance, 0);
			if (!wnd) {
				TRACE("Failed to create system window!\n");
				return;
			}

			dc = GetDC(wnd);

			int pixelFormat;
			BOOL valid;
			UINT numFormats;
			int iAttributes[] = {
				WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
				WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
				WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
				WGL_COLOR_BITS_ARB, 24,
				WGL_ALPHA_BITS_ARB, 8,
				WGL_DEPTH_BITS_ARB, 24,
				WGL_STENCIL_BITS_ARB, 8,
				WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
				0, 0 };

			    // WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
				// WGL_SAMPLES_ARB, 4,                        // Check For 4x Multisampling


			if (wglChoosePixelFormatARB == NULL)
			{
				if (wglGetCurrentContext() == NULL) {
					// 
					MessageBoxA(0, (char*)glGetString(GL_VERSION), "Context lost", 0);

				}


				MessageBoxA(0, (char*)glGetString(GL_VERSION), "Cannot find extension, wglChoosePixelFormatARB", 0);
			}
			else
			{

				valid = wglChoosePixelFormatARB(dc, iAttributes, 0, 1, &pixelFormat, &numFormats);

				int pf = ChoosePixelFormat(dc, &pfd);
				BOOL ok = SetPixelFormat(dc, pixelFormat, &pfd);

			}

			int attr[] = {
				WGL_CONTEXT_MAJOR_VERSION_ARB, 1,
				WGL_CONTEXT_MINOR_VERSION_ARB, 2,
				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, WGL_CONTEXT_DEBUG_BIT_ARB,
				0
			};

			                                                                 
			if (wglCreateContextAttribsARB == NULL)
			{
				MessageBoxA(0, (char*)glGetString(GL_VERSION), "Cannot find extension, wglCreateContextAttribsARB", 0);
				return;
			}


			glrc = wglCreateContextAttribsARB(dc, 0, attr);

			/*
			for (int i = 0; i < 2; ++i) {
			GLuint swap_group = 1;
			if (!wglJoinSwapGroupNV(context.channels[i].dc, swap_group)) {
			TRACE("ERROR: failed to join sawp group");
			}
			if (!wglBindSwapBarrierNV(swap_group, 1)) {
			TRACE("ERROR: failed to bind sawp barrier");
			}
			}
			*/

			// set channel 0 to current so graphics can initiate correctly
			wglMakeCurrent(dc, glrc);

			glDebugMessageCallbackARB = (PFGLDEBUGMESSAGECALLBACKARB) wglGetProcAddress("glDebugMessageCallbackARB");
			if (glDebugMessageCallbackARB == NULL)
			{
				MessageBoxA(0, (char*)glGetString(GL_VERSION), "Unimplemented glDebugMessageCallbackARB", 0);
			}
			else
			{
				glDebugMessageCallbackARB(&gl_debug_msg_proc, 0);
				glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
			}

			ShowWindow(wnd, SW_SHOW);
			UpdateWindow(wnd);

			vgCreateContextSH(800, 600);
		}
static cairo_surface_t *
_cairo_boilerplate_vg_create_surface_glx (const char	*name,
        cairo_content_t	 content,
        double		 width,
        double		 height,
        double		 max_width,
        double		 max_height,
        cairo_boilerplate_mode_t mode,
        int		 id,
        void		**closure)
{
    int rgba_attribs[] = {
        GLX_RGBA,
        GLX_RED_SIZE, 1,
        GLX_GREEN_SIZE, 1,
        GLX_BLUE_SIZE, 1,
        GLX_ALPHA_SIZE, 1,
        GLX_DOUBLEBUFFER,
        None
    };
    int rgb_attribs[] = {
        GLX_RGBA,
        GLX_RED_SIZE, 1,
        GLX_GREEN_SIZE, 1,
        GLX_BLUE_SIZE, 1,
        GLX_DOUBLEBUFFER,
        None
    };
    XVisualInfo *vi;
    Display *dpy;
    Colormap cmap;
    XSetWindowAttributes swa;
    cairo_surface_t *surface;
    cairo_vg_context_t *context;
    vg_closure_glx_t *vgc;

    vgc = malloc (sizeof (vg_closure_glx_t));
    *closure = vgc;

    if (width == 0)
        width = 1;
    if (height == 0)
        height = 1;

    dpy = XOpenDisplay (NULL);
    vgc->dpy = dpy;
    if (vgc->dpy == NULL) {
        fprintf (stderr, "Failed to open display: %s\n", XDisplayName(0));
        free (vgc);
        return NULL;
    }

    if (content == CAIRO_CONTENT_COLOR)
        vi = glXChooseVisual (dpy, DefaultScreen (dpy), rgb_attribs);
    else
        vi = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs);

    if (vi == NULL) {
        fprintf (stderr, "Failed to create RGB, double-buffered visual\n");
        XCloseDisplay (dpy);
        free (vgc);
        return NULL;
    }

    vgc->ctx = glXCreateContext (dpy, vi, NULL, True);
    cmap = XCreateColormap (dpy,
                            RootWindow (dpy, vi->screen),
                            vi->visual,
                            AllocNone);
    swa.colormap = cmap;
    swa.border_pixel = 0;
    vgc->win = XCreateWindow (dpy, RootWindow (dpy, vi->screen),
                              -1, -1, 1, 1, 0,
                              vi->depth,
                              InputOutput,
                              vi->visual,
                              CWBorderPixel | CWColormap, &swa);
    XFreeColormap (dpy, cmap);
    XFree (vi);

    XMapWindow (dpy, vgc->win);

    /* we need an active context to initialise VG */
    glXMakeContextCurrent (dpy, vgc->win, vgc->win, vgc->ctx);

#ifdef USE_AMANITH
    vgInitContextAM (width, height, VG_FALSE, VG_TRUE);
#endif
#ifdef USE_SHIVA
    vgCreateContextSH (width, height);
#endif

    context = cairo_vg_context_create_for_glx (dpy, vgc->ctx);
    vgc->surface = cairo_vg_surface_create (context, content, width, height);
    cairo_vg_context_destroy (context);

    surface = vgc->surface;
    if (cairo_surface_status (surface))
        _cairo_boilerplate_vg_cleanup_glx (vgc);

    return surface;
}
static cairo_surface_t *
_cairo_boilerplate_vg_create_surface_egl (const char	*name,
        cairo_content_t	 content,
        double		 width,
        double		 height,
        double		 max_width,
        double		 max_height,
        cairo_boilerplate_mode_t mode,
        int		 id,
        void		**closure)
{
    int rgba_attribs[] = {
        EGL_RED_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_BLUE_SIZE, 8,
        EGL_ALPHA_SIZE, 8,
        EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
        EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
        None
    };
    int rgb_attribs[] = {
        EGL_RED_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_BLUE_SIZE, 8,
        EGL_ALPHA_SIZE, 8,
        EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE_BIT,
        EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
        EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
        None
    };
    int dummy_attribs[] = {
        EGL_WIDTH, 8, EGL_HEIGHT, 8,
        EGL_NONE
    };
    EGLDisplay *dpy;
    int major, minor;
    EGLConfig config;
    int num_configs;
    EGLContext *egl_context;
    EGLSurface *dummy;
    cairo_vg_context_t *context;
    cairo_surface_t *surface;
    vg_closure_egl_t *vgc;

    dpy = eglGetDisplay (EGL_DEFAULT_DISPLAY);

    if (! eglInitialize (dpy, &major, &minor))
        return NULL;

    eglBindAPI (EGL_OPENVG_API);

    if (! eglChooseConfig (dpy,
                           content == CAIRO_CONTENT_COLOR_ALPHA ?
                           rgba_attribs : rgb_attribs,
                           &config, 1, &num_configs) ||
            num_configs != 1)
    {
        return NULL;
    }

    egl_context = eglCreateContext (dpy, config, NULL, NULL);
    if (egl_context == NULL)
        return NULL;

    /* Create a dummy surface in order to enable a context to initialise VG */
    dummy = eglCreatePbufferSurface (dpy, config, dummy_attribs);
    if (dummy == NULL)
        return NULL;
    if (! eglMakeCurrent (dpy, dummy, dummy, egl_context))
        return NULL;

#ifdef USE_AMANITH
    vgInitContextAM (width, height, VG_FALSE, VG_TRUE);
#endif
#ifdef USE_SHIVA
    vgCreateContextSH (width, height);
#endif

    vgc = xmalloc (sizeof (vg_closure_egl_t));
    vgc->dpy = dpy;
    vgc->ctx = egl_context;
    vgc->dummy = dummy;
    *closure = vgc;

    context = cairo_vg_context_create_for_egl (vgc->dpy, vgc->ctx);
    surface = cairo_vg_surface_create (context, content, width, height);
    cairo_vg_context_destroy (context);

    if (cairo_surface_status (surface))
        _cairo_boilerplate_vg_cleanup_egl (vgc);

    return surface;
}