Пример #1
0
void
init(void) {
    initX();

    int major = 0, minor = 0;
    if (!glXQueryVersion(display, &major, &minor)) {
        std::cerr << "error: failed to obtain GLX version\n";
        exit(1);
    }
    const int requiredMajor = 1, requiredMinor = 3;
    if (major < requiredMajor ||
        (major == requiredMajor && minor < requiredMinor)) {
        std::cerr << "error: GLX version " << requiredMajor << "." << requiredMinor << " required, but got version " << major << "." << minor << "\n";
        exit(1);
    }

    glXQueryExtension(display, &errorBase, &eventBase);
    oldErrorHandler = XSetErrorHandler(errorHandler);

    extensions = glXQueryExtensionsString(display, screen);

#define CHECK_EXTENSION(name) \
    has_##name = checkExtension(#name, extensions)

    CHECK_EXTENSION(GLX_ARB_create_context);
    CHECK_EXTENSION(GLX_ARB_create_context_profile);
    CHECK_EXTENSION(GLX_EXT_create_context_es_profile);
    CHECK_EXTENSION(GLX_EXT_create_context_es2_profile);

#undef CHECK_EXTENSION
}
Пример #2
0
void
init(void) {
    load("libEGL.so.1");

    initX();

    eglExtensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
    if (eglExtensions &&
        checkExtension("EGL_EXT_platform_x11", eglExtensions)) {

        Attributes<EGLint> attribs;
        attribs.add(EGL_PLATFORM_X11_SCREEN_EXT, screen);
        attribs.add(EGL_NONE);

        eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_X11_EXT, display, attribs);
    } else {
        eglDisplay = eglGetDisplay((EGLNativeDisplayType)display);
    }

    if (eglDisplay == EGL_NO_DISPLAY) {
        std::cerr << "error: unable to get EGL display\n";
        XCloseDisplay(display);
        exit(1);
    }

    EGLint major, minor;
    if (!eglInitialize(eglDisplay, &major, &minor)) {
        std::cerr << "error: unable to initialize EGL display\n";
        XCloseDisplay(display);
        exit(1);
    }

    eglExtensions = eglQueryString(eglDisplay, EGL_EXTENSIONS);
    has_EGL_KHR_create_context = checkExtension("EGL_KHR_create_context", eglExtensions);
}
Пример #3
0
int main(int argc, char **argv)
{

  if(argc == 2)
    text = argv[1];
  else {
    printf("give an argument.\n");
    exit(1);
  }

  LOG_MESSAGE("starting xnotify\n");

  initX();

  signal(SIGHUP, sighup_handler);
  signal(SIGINT, sigint_handler);
  
  display_window();

  init_and_start_ev_loop(ConnectionNumber(X.display));

  cleanup();

  return 0;
}
/*!****************************************************************************
 @Function		initApplication
 @Return		bool		1 if no error occured
 @Description		Code in initApplication() is used to initialize egl.
******************************************************************************/
int initApplication()
{
	#if defined XORG_BUILD
	initX();
	#endif
	if (initEGL(NULL, NULL, 0)) 
	{
        	printf("ERROR: init EGL failed\n");
	        return (0);
    	}
	return 1;
}
Пример #5
0
void
init(void) {
    initX();

    int major = 0, minor = 0;
    glXQueryVersion(display, &major, &minor);
    glxVersion = (major << 8) | minor;

    extensions = glXQueryExtensionsString(display, screen);

#define CHECK_EXTENSION(name) \
    has_##name = checkExtension(#name, extensions)

    CHECK_EXTENSION(GLX_ARB_create_context);
    CHECK_EXTENSION(GLX_ARB_create_context_profile);
    CHECK_EXTENSION(GLX_EXT_create_context_es_profile);
    CHECK_EXTENSION(GLX_EXT_create_context_es2_profile);

#undef CHECK_EXTENSION
}
Пример #6
0
int openwindow(int swidth,int sheight)

{
    
    static int firsttime = 1;
    
    void initX(),beep();
    
    int createGC(Window,GC*);
    
    XSetWindowAttributes    theWindowAttributes;
    XSizeHints              theSizeHints;
    unsigned        long    theWindowMask;
    
    if(firsttime) {
	firsttime = 0;
	initX();
    }
    ww = swidth;
    wh = sheight;
    
    if(swidth <= 0) swidth = 10;
    if(sheight <= 0) sheight = 10;
    
    theWindowMask = CWBackPixel | CWBorderPixel | CWOverrideRedirect;
    
    theWindowAttributes.border_pixel = theBlackPixel
    = BlackPixel( theDisplay,theScreen );
    theWindowAttributes.background_pixel = theWhitePixel
    = WhitePixel( theDisplay,theScreen );
    theWindowAttributes.override_redirect = False;
    
    
    theWindow = XCreateWindow(theDisplay,
			      RootWindow(theDisplay,theScreen),
			      orgx,orgy,
			      swidth,sheight,
			      BORDER_WIDTH,
			      theDepth,
			      InputOutput,
			      CopyFromParent,
			      theWindowMask,
			      &theWindowAttributes);
    
    theSizeHints.flags      =       PPosition | PSize;
    theSizeHints.x          =       orgx;
    theSizeHints.y          =       orgy;
    theSizeHints.width      =       swidth;
    theSizeHints.height     =       sheight;
    
    XSetNormalHints( theDisplay, theWindow, &theSizeHints );
    
    if (createGC(theWindow, &theGC) == 0 ) {
	XDestroyWindow(theDisplay, theWindow);
	beep();
	return(0);
    }
    
    XMapWindow( theDisplay, theWindow );
    
    XFlush( theDisplay );
    getcolors();
    return( 1 );
}
Пример #7
0
int main(int argc, char **argv)
{
	int x, y;

	Window win1;
	GC gc1;
	XEvent event;
	XImage *ximg1;

	int flag;
	struct IplImage *prev1, *curr1, *motion;
	struct IplDev *dev1;

	time_t start, end;
	int f;

	f = 0;
	start = 0;
	end = 0;
	
	x = 0;
	y = 0;
	initX();
	getXinfo();
	win1 = openWindow(500, 500, 640, 480, 0, &gc1);
	XNextEvent(theDisplay, &event);
	ximg1 = XGetImage(theDisplay, win1, x, y, 640, 480, AllPlanes, ZPixmap);
	if(XInitImage(ximg1) == 0) {
		fprintf(stderr,"error: XInitImage\n");
		return 1;
	}

	printf("first xgetimage done\n");

	if ((dev1 = ipl_opendev(0, IPL_RGB_MODE)) == NULL) {
		printf("error while creating device 0\n");
		return 1;
	}

	if (ipl_setparams(dev1, 320, 240, IPL_FORCE_SCALE_ON) < 0) {
		fprintf(stderr, "error on changing cam params\n");
		free(dev1);
		return 1;
	}
	if ((prev1 = ipl_getframe(dev1)) == NULL) {
		printf("error capturing prev1\n");
		return 1;
	}


	flag = 1;
	start = time(NULL);
	
	while (flag) {
		f++;	
		end = time(NULL);
		if (end - start >= 1.0) {
			printf("fps = %i\n", f);
			f = 0;
			start = end;
		}
	
		if ((curr1 = ipl_getframe(dev1)) == NULL) {
			printf("error capturing curr1\n");
			return 1;
		}
		motion = framescompare(curr1, prev1);
		ipl_scaleimg(&motion, 640, 480);
		camera_shoot(motion, ximg1, gc1, win1, x, y);
		ipl_freeimg(&prev1);
		prev1 = curr1;


		ipl_freeimg(&motion);
		XCheckTypedWindowEvent(theDisplay, win1, ButtonPress, &event);
		if (event.xbutton.button == 1)
			flag = 0;
	}

	ipl_freeimg(&curr1);
	XDestroyImage(ximg1);
	XDestroyWindow(theDisplay, win1);

	quitX();


	return 0;
}
Пример #8
0
int main(int argc, char* argv[])
{
    std::shared_ptr<Empty> blank;
    std::shared_ptr<Program> prg(new Program());

    std::shared_ptr<SharedDecl> shDecl1(new SharedDecl("y", blank));
    prg->Add(shDecl1);

    std::shared_ptr<Node> initX(new Atom("2"));
    std::shared_ptr<SharedDecl> shDecl2(new SharedDecl("x", initX));
    prg->Add(shDecl2);

    std::shared_ptr<Sub> sub1(new Sub("Main"));
    sub1->AddParam("a");
    sub1->AddParam("b");
    prg->Add(sub1);

    std::shared_ptr<Atom> atomA(new Atom("a"));
    std::shared_ptr<Atom> atomB(new Atom("b"));
    std::shared_ptr<BinaryOp> initRes(new BinaryOp("add", atomA, atomB));
    std::shared_ptr<VarDecl> resDecl(new VarDecl("res", initRes));
    sub1->Add(resDecl);

    std::shared_ptr<Atom> atom3i(new Atom("3"));
    std::shared_ptr<Atom> atom5i(new Atom("5"));
    std::shared_ptr<BinaryOp> newParam(new BinaryOp("add", atom3i, atom5i));
    std::shared_ptr<Allocation> allocat(new Allocation(newParam));
    std::shared_ptr<Atom> atomArr(new Atom("arr"));
    std::shared_ptr<Assignation> asignNew3(new Assignation(atomArr, allocat));
    sub1->Add(asignNew3);

    std::shared_ptr<Atom> atomArrBis(new Atom("arr"));
    std::shared_ptr<Deallocation> deallocat(new Deallocation(atomArrBis));
    sub1->Add(deallocat);

    std::shared_ptr<Atom> atomC(new Atom("res"));
    std::shared_ptr<BinaryOp> subCsumAB(new BinaryOp("substract", atomC, initRes));
    std::shared_ptr<Assignation> incC(new Assignation(atomC, subCsumAB));
    sub1->Add(incC);

    std::shared_ptr<Atom> atom0(new Atom("0"));
    std::shared_ptr<BinaryOp> cond1cond(new BinaryOp("equals", atomC, atom0));
    std::shared_ptr<If> cond1(new If(cond1cond, "10", "20"));
    sub1->Add(cond1);

    std::shared_ptr<Atom> atom1(new Atom("1"));
    std::shared_ptr<Atom> atom10(new Atom("10"));
    std::shared_ptr<For> for1(new For("i", atom1, atom10, atom1));
    sub1->Add(for1);

    std::shared_ptr<BinaryOp> addC1(new BinaryOp("add", atomC, atom1));
    std::shared_ptr<Assignation> incResActually(new Assignation(atomC, addC1));
    for1->Add(incResActually);

    std::shared_ptr<Loop> loop1(new Loop(cond1cond));
    loop1->Add(for1); // don't double reference ever in practice...
    loop1->Add(addC1);
    sub1->Add(loop1);

    std::shared_ptr<Call> call1(new Call("testFun", ""));
    call1->AddParam(atomA);
    call1->AddParam(addC1);
    sub1->Add(call1);

    std::shared_ptr<Return> ret1(new Return(atom0));
    sub1->Add(ret1);

    XMLDumpVisitor v;
    prg->Accept(&v);

    return 0;
}
Пример #9
0
int GWindow::screenMaxY() {
    if (m_Display == 0)
        initX();
    return XDisplayHeight(m_Display, m_Screen);
}
Пример #10
0
int GWindow::screenMaxX() {
    if (m_Display == 0)
        initX();
    return XDisplayWidth(m_Display, m_Screen);
}
Пример #11
0
void GWindow::createWindow(
    GWindow* parentWindow /* = 0 */,                // parent window
    int borderWidth       /* = DEFAULT_BORDER_WIDTH */,
    unsigned int wndClass /* = InputOutput */,      // InputOnly, CopyFromParent
    Visual* visual        /* = CopyFromParent */,
    unsigned long attributesValueMask /* = 0 */,    // which attr. are defined
    XSetWindowAttributes* attributes  /* = 0 */     // attributes structure
) {
    // Include a window in the head of the window list
    link(*(m_WindowList.next));
    m_WindowList.link(*this);

    m_NumWindows++;
    m_NumCreatedWindows++;

    // Open a display, if necessary
    if (m_Display == 0)
        initX();

    // Create window and map it

    //+++
    // printf("Creating window: width=%d, height=%d\n",
    //     m_IWinRect.width(), m_IWinRect.height());
    //+++

    if (m_IWinRect.left() != 0 || m_IWinRect.top() != 0) {
        int x = m_IWinRect.left();
        int y = m_IWinRect.top();
        int w = m_IWinRect.width();
        int h = m_IWinRect.height();
        m_WindowPosition.x += x;
        m_WindowPosition.y += y;
        m_IWinRect = I2Rectangle(0, 0, w, h);
    }

    if (m_bgColorName != 0) {
        XColor bg;
        XParseColor(
            m_Display,
            DefaultColormap(m_Display, m_Screen),
            m_bgColorName,
            &bg
        );
        XAllocColor(
            m_Display, DefaultColormap(m_Display, m_Screen), &bg
        );
        m_bgPixel = bg.pixel;
    } else {
        m_bgPixel = WhitePixel(m_Display, m_Screen);
    }

    if (m_fgColorName != 0) {
        XColor fg;
        XParseColor(
            m_Display,
            DefaultColormap(m_Display, m_Screen),
            m_fgColorName,
            &fg
        );
        XAllocColor(
            m_Display, DefaultColormap(m_Display, m_Screen), &fg
        );
        m_fgPixel = fg.pixel;
    } else {
        m_fgPixel = BlackPixel(m_Display, m_Screen);
    }

    m_BorderWidth = borderWidth;

    /*...
    m_Window = XCreateSimpleWindow(
        m_Display, 
        DefaultRootWindow(m_Display), 
        m_WindowPosition.x,
        m_WindowPosition.y,
        m_IWinRect.width(),
        m_IWinRect.height(),
        m_BorderWidth,
        m_fgPixel,
        m_bgPixel
    );
    ...*/

    Window parent;
    if (parentWindow != 0 && parentWindow->m_Window != 0)
        parent = parentWindow->m_Window;
    else
        parent = DefaultRootWindow(m_Display);
    XSetWindowAttributes windowAttributes;
    XSetWindowAttributes* winAttributes = &windowAttributes;
    if (attributesValueMask != 0 && attributes != 0)
        winAttributes = attributes;
    else
        memset(&windowAttributes, 0, sizeof(windowAttributes));

    m_Window = XCreateWindow(
        m_Display,
        parent,
        m_WindowPosition.x,
        m_WindowPosition.y,
        m_IWinRect.width(),
        m_IWinRect.height(),
        m_BorderWidth,
        CopyFromParent,
        wndClass,
        visual,
        attributesValueMask,
        winAttributes
    );

    m_WindowCreated = true;
    XSetStandardProperties(
        m_Display,
        m_Window,
        m_WindowTitle,          // Window name
        m_WindowTitle,          // Icon name
        None,                   // Icon pixmap
        0,                      // argv
        0,                      // argc
        0                       // XSizeHints
    );
    XSelectInput(
        m_Display,
        m_Window,
        ExposureMask | ButtonPressMask | ButtonReleaseMask
            | KeyPressMask | PointerMotionMask
            | StructureNotifyMask       // For resize event
            | SubstructureNotifyMask
            | FocusChangeMask
    );
    m_GC = XCreateGC(
        m_Display,
        m_Window,
        0,
        0
    );
    XSetBackground(
        m_Display,
        m_GC,
        m_bgPixel
    );
    XSetForeground(
        m_Display,
        m_GC,
        m_fgPixel
    );
    XClearWindow(
        m_Display,
        m_Window
    );
    XMapRaised(
        m_Display,
        m_Window
    );

    // To prevent application closing on pressing the window close box
    XSetWMProtocols(
        m_Display, m_Window,
        &m_WMDeleteWindowAtom, 1
    );

    // printf("In createWindow: m_Window = %d\n", (int) m_Window);
}