Example #1
0
void MyApp::renderScene()
{
	glPushMatrix();
	//gl::translate( -(getWindowSize() * 0.5) );
	
	glEnable( GL_LIGHTING );

	gl::enableDepthRead();
	gl::enableDepthWrite();

	sf::gl::clear( Color( 0, 0, 0 ) );
	sf::gl::color( Color::white() );

	// ciSunflow has a default sunlight. This would create a light bulb
	sunflow.setLight( *mLight, light_specular, 20.0 );

	//sf::gl::drawSphere( Vec3f::zero(), getWindowHeight()*0.25 );

	Vec3f start = Vec3f( -(getWindowSize() * 0.5), 0 );
	Vec3f sz = Vec3f( getWindowWidth()/mGridSize.x, getWindowHeight()/mGridSize.y, getWindowWidth()/mGridSize.x );
	for (int x = 0 ; x < mGridSize.x ; x++ )
	{
		for (int y = 0 ; y < mGridSize.y ; y++ )
		{
			Vec3f p = start + sz * Vec3f( x+0.5, y+0.5, -0.5 );
			if ( ((x%2)&&!(y%2)) || (!(x%2)&&(y%2)) )
			{
				sunflow.setShader( "default" );
				p.z -= sz.z * 0.5;
				sf::gl::drawCube( p, sz*0.5 );
			}
			else
			{
				sunflow.setShader( "mirror" );
				p.z += sz.z * 0.5;
				sf::gl::drawSphere( p, sz.x*0.5 );
			}
		}
	}
	
	glPopMatrix();

}
//--------------------------------------------------------------
void FingerTracker::addToFluid( Vec2f pos, Vec2f vel, bool addColor, bool addForce ) {
    float speed = vel.x * vel.x  + vel.y * vel.y * getWindowAspectRatio() * getWindowAspectRatio();
    if(speed > 0) {
		pos.x = constrain(pos.x, 0.0f, 1.0f);
		pos.y = constrain(pos.y, 0.0f, 1.0f);
        const float colorMult = 100;
        const float velocityMult = 30;
        int index = fluidSolver.getIndexForPos(pos);
		if(addColor) {
			Color drawColor( CM_HSV, ( getElapsedFrames() % 360 ) / 360.0f, 1, 1 );
            fluidSolver.addColorAtIndex(index, drawColor * colorMult);
            if(drawParticles) {
                particleSystem.addParticlesWithVelc( pos*Vec2f(getWindowSize()), vel*Vec2f(getWindowSize()), 2 );
            }
		}
		if(addForce)
			fluidSolver.addForceAtIndex(index, vel * velocityMult);
    }
}
Example #3
0
void linenoiseClearScreen(void)
{
    /* XXX: This is ugly. Should just have the caller pass a handle */
    struct current current;

    current.outh = GetStdHandle(STD_OUTPUT_HANDLE);

    if (getWindowSize(&current) == 0) {
        COORD topleft = { 0, 0 };
        DWORD n;

        FillConsoleOutputCharacter(current.outh, ' ',
            current.cols * current.rows, topleft, &n);
        FillConsoleOutputAttribute(current.outh,
            FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN,
            current.cols * current.rows, topleft, &n);
        SetConsoleCursorPosition(current.outh, topleft);
    }
}
Example #4
0
 fzOrientation Director::getOrientation() const
 {
     if(m_orientation == kFZOrientation_Auto) {
         
         const fzSize &windowSize = getWindowSize();
         fzSize canvasSize = (m_originalCanvasSize == kFZSize_Auto) ? windowSize : m_originalCanvasSize;
         
         fzFloat windowRate = windowSize.width/windowSize.height;
         fzFloat canvasRate = canvasSize.width/canvasSize.height;
         
         if(canvasRate == 1.0f || windowRate == 1.0f)
             return kFZOrientation_Portrait;
         
         if((canvasRate < 1.0f) != (windowRate < 1.0f))
             return kFZOrientation_LandscapeLeft;
         else
             return kFZOrientation_Portrait;
     }
     return m_orientation;
 }
void initEditor() {
  E.cx = 0;
  E.cy = 0;
  E.rx = 0;
  E.rowoff = 0;
  E.coloff = 0;
  E.numrows = 0;
  E.row = NULL;
  E.dirty = 0;
  E.filename = NULL;
  E.statusmsg[0] = '\0';
  E.statusmsg_time = 0;
  E.syntax = NULL;

  if (getWindowSize(STDIN_FILENO, STDOUT_FILENO, &E.screenrows, &E.screencols) == -1) {
    perror("Unable to query the screen for size (columns / rows)");
    exit(1);
  }
  E.screenrows -= 2;
}
Example #6
0
void CMainFrame::OnSize(UINT nType, int cx, int cy) {
  __super::OnSize(nType, cx, cy);
  if(IsIconic())  {
    return;
  }

  TextView *view1 = getActiveTextView();
  TextView *view2 = view1 ? view1->getPartner() : NULL;
  if(view1) view1->savePositionState();
  if(view2) view2->savePositionState();

  if(m_wndSplitter.IsWindowVisible()) {
    m_wndSplitter.SetScrollStyle(0);

    setRelativeWidth(cx);
    m_wndSplitter.SetScrollStyle(0);
    m_wndSplitter.RecalcLayout();
//    m_wndSplitter.GetPane(0,0)->ShowScrollBar(SB_BOTH,FALSE);
//    m_wndSplitter.GetPane(0,0)->ShowScrollBar(SB_BOTH,FALSE);
    getOptions().m_windowSize = getWindowSize(this);
  }
}
Example #7
0
///////////////////////////////////////////////////////////
//
// Get the current image's pixel displayed in the center of
//  the window
//
///////////////////////////////////////////////////////////
void view::getCenterPoint(imbxInt32* pCenterPointX, imbxInt32* pCenterPointY)
{
	// Reset the result values
	///////////////////////////////////////////////////////////
	*pCenterPointX = 0;
	*pCenterPointY = 0;

	if(m_originalImage == 0)
	{
		return;
	}

	imbxUint32 imageSizeX, imageSizeY;
	m_originalImage->getSize(&imageSizeX, &imageSizeY);

	// Nothing happens if the image is not valid
	///////////////////////////////////////////////////////////
	if(m_rightPosition - m_leftPosition == 0 || m_bottomPosition - m_topPosition == 0)
	{
		return;
	}

	// Get the window's width
	///////////////////////////////////////////////////////////
	imbxUint32 windowWidth  = 0;
	imbxUint32 windowHeight = 0;
	getWindowSize(&windowWidth, &windowHeight);

	// Get the scroll position
	///////////////////////////////////////////////////////////
	imbxInt32 scrollX = 0;
	imbxInt32 scrollY = 0;
	getScrollPosition(&scrollX, &scrollY);

	// Calculate the actual center point
	///////////////////////////////////////////////////////////
	*pCenterPointX = windowPosToImageX(scrollX + windowWidth / 2);
	*pCenterPointY = windowPosToImageY(scrollY + windowHeight / 2);
}
int main(){
	//allocateCircularBuffer(10);
	//int avail = availableWindowSize();
	//printf("avail: %d\n", avail);
	allocateCircularBuffer(10);
	int avail = availableWindowSize();
	printf("avail: %d\n", avail);
	avail = getWindowSize();
	printf("window Size %d \n", avail);
	ServerBufferNode *a = findSeqNode(0);
	if(a == NULL){
		printf("NULL\n");
	}
	printf("valid\n");

	//allocateCircularBuffer(1);
	//avail = availableWindowSize();
	//printf("avail: %d\n", avail);
	//printf("avail: %d\n", avail);
	//printf("%d\n", sizeof(MsgHdr));
	//printf("%d\n", sizeof(ServerBufferNode));
}
Example #9
0
bool ghosts::render()
{
	glm::vec2 window_size(getWindowSize());
	glm::mat4 projection_matrix = glm::perspectiveFov(glm::pi<float>() * 0.25f, window_size.x, window_size.y, 0.1f, 100.0f);

	graphics::renderer::clear(window_size, glm::vec4(.95f));

	// light: direction light.xyz, intensity light.w
	//glm::vec4 light_vec(-1.f, -2.f, 0.f, 100.f);
	glm::vec4 light_vec(-1.f, -1.f, 0.f, 100.f);

	// simulate
	for (auto model : m_Models) {
		model->simulate(0.016f);
	}

	// render
	for (auto model : m_Models) {
		model->render(projection_matrix, view(), light_vec);
	}

	return true;
}
void WindowedBlockModel::lastPage() {
  quint32 windowBegin = getWindowBegin();
  quint32 windowSize = getWindowSize();
  if (windowSize == 0) {
    return;
  }

  quint32 lowerThreshold = sourceModel()->index(0, 0).data(BlockchainModel::ROLE_BLOCK_HEIGHT).toUInt();
  quint32 upperThreshold = sourceModel()->index(sourceModel()->rowCount() - 1, 0).data(BlockchainModel::ROLE_BLOCK_HEIGHT).toUInt();

  quint32 windowEnd = upperThreshold;
  if (upperThreshold < lowerThreshold + windowSize - 1) {
    windowBegin = lowerThreshold;
  } else {
    windowBegin = windowEnd - windowSize + 1;
  }

  IBlockChainExplorerAdapter* blockChainExplorerAdapter = m_cryptoNoteAdapter->getNodeAdapter()->getBlockChainExplorerAdapter();
  if (blockChainExplorerAdapter != nullptr) {
    blockChainExplorerAdapter->preloadBlocks(windowBegin, windowEnd);
    WindowedBlockModel::setWindowBegin(windowBegin);
  }
}
Example #11
0
/**
 * Resize the option buttons so that they fit vertically within the MenuView.
 * <p>
 * Only take this action for buttons that fall within the current visible window of option.
 * <p>
 * If the visible option count is set to 0, it will fit all options into the area. Otherwise, it will fit the visible
 * option count of options into the area.
 */
void MenuView::sizeButtons() {
    if (!buttons.empty()) {
        for (auto button : buttons) {
            button->hide();
        }

        auto windowSize = getWindowSize();
        auto slotIndex = 0;
        for (auto optionIndex = getWindowTopIndex(); optionIndex < getWindowTopIndex() + windowSize; optionIndex++) {
            if (optionIndex < buttons.size()) {
                auto button = buttons[optionIndex];
                // Button X is the same as the MenuView X
                button->setX(getX());

                // Button Width is the same as the MenuView Width
                button->setWidth(getWidth());

                // Button Height is the MenuView height less the two arrows divided by the window size
                uint16_t buttonHeight = getHeight();
                buttonHeight -= upArrowView->getHeight();
                buttonHeight -= downArrowView->getHeight();
                buttonHeight /= windowSize;
                button->setHeight(buttonHeight);

                // Button Y is relative to the bottom edge of the up arrow button
                uint16_t buttonY = getY();
                buttonY += upArrowView->getHeight();
                buttonY += slotIndex * button->getHeight();
                button->setY(buttonY);

                button->show();
                slotIndex++;
            }
        }
    }
}
	void TextureToolWindow::addTrackbar(const std::string& name, EventReceiver* eventReceiver,
										const UINT minValue, const UINT maxValue, const UINT startValue)
	{
		const UINT count  = (UINT)m_items.size();
		const UINT width  = m_clientWidth - 2 * m_itemMargin;
		const UINT x	  = m_itemMargin;
			  UINT y	  = m_textureButtonSize + m_loadFileButtonHeight + m_trackbarCount * (m_trackbarHeight + m_itemMargin + m_trackbarTextSize) + 4 * m_itemMargin;
		const UINT id	  = m_itemIDStart + count;

		HWND hText = CreateWindow("STATIC", name.c_str(), WS_VISIBLE | WS_CHILD,
								  x, y, width, m_trackbarTextSize,
								  m_hWnd, NULL, m_hInstance, NULL);

		HFONT hFont = CreateFont(m_trackbarTextSize, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE,
								 ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
								 DEFAULT_PITCH | FF_DONTCARE, "Tahoma");
		SendMessage(hText, WM_SETFONT, (WPARAM)hFont, TRUE);

		y += m_trackbarTextSize;

		HWND hTrackbar = CreateWindow(TRACKBAR_CLASS, NULL, WS_CHILD | WS_VISIBLE | TBS_TOOLTIPS,
									  x, y, width, m_trackbarHeight, m_hWnd, (HMENU)id, m_hInstance, NULL);

		SendMessage(hTrackbar, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(minValue, maxValue));
		SendMessage(hTrackbar, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)startValue);

		m_items.push_back(EventElement(name, eventReceiver));

		m_trackbarCount++;

		m_clientHeight = m_textureButtonSize + m_loadFileButtonHeight + m_trackbarCount * (m_trackbarHeight + m_itemMargin + m_trackbarTextSize) + 4 * m_itemMargin;

		const POINT windowSize	   = getWindowSize();
		const POINT windowPosition = getWindowPosition();
		SetWindowPos(m_hWnd, HWND_TOP, windowPosition.x, windowPosition.y, windowSize.x, windowSize.y, NULL);
	}
Example #13
0
void CButton::draw()
{
    float *pos = getPosition();

    float width, height;

    getWindowSize(&width,&height);

    glEnable(GL_TEXTURE_2D);

    if(pressed)
    {
        glBindTexture(GL_TEXTURE_2D, pressedId);
    }
    else
    {
    if(selected)
    {
        glBindTexture(GL_TEXTURE_2D, selectedId);
    }
    else
    {
        glBindTexture(GL_TEXTURE_2D, normalId);
    }
    }

    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex2f(pos[0],pos[1]);
    glTexCoord2f(1.0f, 0.0f); glVertex2f(pos[0]+width,pos[1]);
    glTexCoord2f(1.0f, 1.0f); glVertex2f(pos[0]+width,pos[1]+height);
    glTexCoord2f(0.0f, 1.0f); glVertex2f(pos[0],pos[1]+height);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_TEXTURE_2D);
}
	void NewTerrainWindow::addButton(const std::string& name, EventReceiver* eventReceiver)
	{
		const UINT count = (UINT)m_items.size();
		const UINT x	 = (count % 2) * (m_dropdownListWidth + m_itemMargin) + m_itemMargin;
		const UINT y	 = (count / 2) * (m_dropdownListTextSize + m_dropdownListHeight + m_itemMargin) + m_itemMargin;
		const UINT id	 = m_itemIDStart + count;

		HWND hButton = CreateWindow("BUTTON", name.c_str(), WS_CHILD | WS_VISIBLE | BS_PUSHLIKE,
									x, y, m_dropdownListWidth, m_buttonHeight, m_hWnd, (HMENU)id, m_hInstance, NULL);

		HFONT hFont = CreateFont(m_buttonTextSize, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE,
								 ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
								 DEFAULT_PITCH | FF_DONTCARE, "Tahoma");
		SendMessage(hButton, WM_SETFONT, (WPARAM)hFont, TRUE);

		m_items.push_back(EventElement(name, eventReceiver));

		if (!(count % 2))
			m_clientHeight += m_buttonHeight + m_itemMargin;

		const POINT windowSize	   = getWindowSize();
		const POINT windowPosition = getWindowPosition();
		SetWindowPos(m_hWnd, HWND_TOP, windowPosition.x, windowPosition.y, windowSize.x, windowSize.y, NULL);
	}
Example #15
0
void LinuxEnvironment::enableFullscreen()
{
	if (m_bFullScreen) return;

	// backup
	if (m_vPrevDisableFullscreenWindowSize != getWindowSize())
	{
		m_vLastWindowPos = getWindowPos();
		m_vLastWindowSize = getWindowSize();
	}

	// handle resizability (force enable while fullscreen)
	m_bFullscreenWasResizable = m_bResizable;
	setWindowResizable(true);

	// disable window decorations
    Hints hints;
    Atom property;
    hints.flags = 2; // specify that we're changing the window decorations
    hints.decorations = 0; // 0 (false) = disable decorations
    property = XInternAtom(m_display, "_MOTIF_WM_HINTS", True);
    XChangeProperty(m_display, m_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);

	// set size to fill entire screen (also fill borders)
	// the "x" and "y" members of "attributes" are the window's coordinates relative to its parent, i.e. to the decoration window
	XWindowAttributes attributes;
	XGetWindowAttributes(m_display, m_window, &attributes);
	XMoveResizeWindow(m_display,
			m_window,
			-attributes.x,
			-attributes.y,
			(unsigned int)getNativeScreenSize().x,
			(unsigned int)getNativeScreenSize().y);

    // suggest fullscreen mode
	Atom atom = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", True);
	XChangeProperty(
		m_display, m_window,
		XInternAtom(m_display, "_NET_WM_STATE", True),
		XA_ATOM, 32, PropModeReplace,
		(unsigned char*)&atom, 1);

	// get identifiers for the provided atom name strings
	Atom wm_state = XInternAtom(m_display, "_NET_WM_STATE", False);
	Atom fullscreen = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False);

	XEvent xev;
	memset(&xev, 0, sizeof(xev));

	xev.type                 = ClientMessage;
	xev.xclient.window       = m_window;
	xev.xclient.message_type = wm_state;
	xev.xclient.format       = 32;
	xev.xclient.data.l[0]    = 1; // enable fullscreen (1 == true)
	xev.xclient.data.l[1]    = fullscreen;

	// send an event mask to the X-server
	XSendEvent(
		m_display,
		DefaultRootWindow(m_display),
		False,
		SubstructureNotifyMask,
		&xev);

	// force top window
	focus();

	m_bFullScreen = true;
}
Example #16
0
void OgreWindowProvider::windowResized(Ogre::RenderWindow* rw)
{
	unsigned int width, height;
	getWindowSize(width, height);
	Input::getSingleton().setGeometry(width, height);
}
Example #17
0
    void Director::updateViewRect()
    {
        if(!(m_dirtyFlags & kFZDDirty_viewPort))
            return;
        
        if(m_windowSize == FZSizeZero && m_originalCanvasSize == FZSizeZero)
            setFullscreen();
        else if(m_windowSize == FZSizeZero)
            setWindowSize(m_originalCanvasSize);
        
        fzSize windowSize = getWindowSize();
        fzSize canvasSize = (m_originalCanvasSize == FZSizeZero) ? windowSize : m_originalCanvasSize;
        fzOrientation orientation = getOrientation();
        
        if(orientation == kFZOrientation_LandscapeLeft ||
           orientation == kFZOrientation_LandscapeRight)
        {
            FZ_SWAP(canvasSize.width, canvasSize.height);
        }
                
        fzFloat windowRate = windowSize.width/windowSize.height;
        fzFloat canvasRate = canvasSize.width/canvasSize.height;
        fzSize newCanvasSize = canvasSize; // could be the same

        if(windowRate == canvasRate) {
            
            // No resizing because the canvas and window rate is the same.
            m_renderingRect = fzRect(FZPointZero, windowSize);
        
        }else{
            
            // The window and the canvas rate is different, so we have to apply
            // the proper resizing algorythm
            switch (m_resizeMode) {
                    
                case kFZResizeMode_None:
                {
                    m_renderingRect.size = canvasSize;
                    m_renderingRect.origin = (windowSize - canvasSize)/2;
                    
                    break;
                }
                case kFZResizeMode_Expand:
                {
                    m_renderingRect = fzRect(FZPointZero, windowSize);
                    
                    break;
                }
                case kFZResizeMode_Fit:
                {
                    if(canvasRate > windowRate)
                    {
                        m_renderingRect.size.width = windowSize.width;
                        m_renderingRect.size.height = canvasSize.height * windowSize.width/canvasSize.width;
                        m_renderingRect.origin = fzPoint(0, (windowSize.height-m_renderingRect.size.height)/2);
                    }else{
                        m_renderingRect.size.height = windowSize.height;
                        m_renderingRect.size.width = canvasSize.width * windowSize.height/canvasSize.height;
                        m_renderingRect.origin = fzPoint((windowSize.width-m_renderingRect.size.width)/2, 0);
                    }
                    break;
                }
                case kFZResizeMode_FitFill:
                {
                    if(canvasRate > windowRate)
                        newCanvasSize.height = canvasSize.width / windowRate;
                    else
                        newCanvasSize.width = canvasSize.height * windowRate;
                                        
                    m_renderingRect = fzRect(FZPointZero, windowSize);
                    break;
                }
                case kFZResizeMode_IntFit:
                {                    
                    fzFloat factorX = windowSize.width / canvasSize.width;
                    fzFloat factorY = windowSize.height / canvasSize.height;
                    fzFloat factor = MIN(factorX, factorY);
                    factor = (factor >= 1.0f) ? static_cast<fzInt>(factor) : factor;
                    
                    m_renderingRect.size = canvasSize * factor;
                    m_renderingRect.origin = (windowSize - m_renderingRect.size)/2;
                    
                    break;
                }
                case kFZResizeMode_IntFitFill:
                {
                    fzFloat factorX = windowSize.width / canvasSize.width;
                    fzFloat factorY = windowSize.height / canvasSize.height;
                    fzFloat factor = MIN(factorX, factorY);
                    factor = (factor >= 1.0f) ? static_cast<fzInt>(factor) : factor;

                    newCanvasSize = windowSize / factor;
                    
                    m_renderingRect = fzRect(FZPointZero, windowSize);
                    
                    break;
                }
                    
                default:
                    break;
            }
        }
        m_canvasSize = newCanvasSize;

        if(orientation == kFZOrientation_LandscapeLeft ||
           orientation == kFZOrientation_LandscapeRight)
        {
            FZ_SWAP(m_canvasSize.width, m_canvasSize.height);
        }
        
        // FACTORS
        fzSize viewPort = getViewPort();
        fzFloat factorX = viewPort.width / newCanvasSize.width;
        fzFloat factorY = viewPort.height / newCanvasSize.height;
        
        
        // COMPUTE FINAL FACTOR
        fzFloat newFactor = roundf(MAX(MAX(factorX, factorY), 1));
        if(newFactor > DeviceConfig::Instance().getMaxFactor())
            newFactor = DeviceConfig::Instance().getMaxFactor();
        
        if(newFactor > m_resourcesFactor)
        {
            TextureCache::Instance().removeAllTextures();
            FontCache::Instance().removeAllFonts();
        }
        m_resourcesFactor = newFactor;
        
        m_dirtyFlags &= ~kFZDDirty_viewPort;
        m_dirtyFlags |= kFZDDirty_projection;
        
        
        // Notify changes to the OS Wrapper
        OSW::setOrientation(orientation);
        OSW::updateWindow();
    }
Example #18
0
 bool Director::isFullscreen() const
 {
     return (getWindowSize() * m_screenFactor == m_screenSize);
 }
Example #19
0
inline ci::Vec2f getWindowCenter() { return getWindowSize() * 0.5; }
void SimpleParticlesApp::resize()
{
	mEmitterController.createConstraints( getWindowSize() );
}
Example #21
0
void NanoApp::resize()
{
   camera.setPerspective (60.0f, getWindowAspectRatio(), 0.1f, 1000.0f);
   cameraUI.setCamera (&camera);
   gui->resize (getWindowSize());
}
Example #22
0
void Warp::resize()
{
	resize( getWindowSize() );
}
Example #23
0
bool GLES2Renderer::initTexter()
{
	Renderer::initTexter();

	PxU32 width, height;
	getWindowSize(width, height);
	const PxU32 MIN_CHARACTER_WIDTH = 8;
	const PxU32 TEXT_MAX_VERTICES = 16 * (width / MIN_CHARACTER_WIDTH);
	const PxU32 TEXT_MAX_INDICES = TEXT_MAX_VERTICES * 1.5f;

	// initialize vertex buffer -- will be used by all texts
	RendererVertexBufferDesc vbdesc;
	vbdesc.hint = RendererVertexBuffer::HINT_STATIC;
	vbdesc.maxVertices = TEXT_MAX_VERTICES;
	vbdesc.semanticFormats[RendererVertexBuffer::SEMANTIC_POSITION] = RendererVertexBuffer::FORMAT_FLOAT3;
	vbdesc.semanticFormats[RendererVertexBuffer::SEMANTIC_TEXCOORD0] = RendererVertexBuffer::FORMAT_FLOAT2;
	vbdesc.semanticFormats[RendererVertexBuffer::SEMANTIC_COLOR] = RendererVertexBuffer::FORMAT_COLOR_NATIVE;
	m_textVertexBuffer = createVertexBuffer(vbdesc);
	RENDERER_ASSERT(m_textVertexBuffer, "Failed to create Vertex Buffer.");
	// initialize index buffer
	RendererIndexBufferDesc inbdesc;
	inbdesc.hint = RendererIndexBuffer::HINT_STATIC;
	inbdesc.format = RendererIndexBuffer::FORMAT_UINT16;
	inbdesc.maxIndices = TEXT_MAX_INDICES;
	m_textIndexBuffer = createIndexBuffer(inbdesc);
	RENDERER_ASSERT(m_textIndexBuffer, "Failed to create Instance Buffer.");
	RendererMeshDesc meshdesc;
	meshdesc.primitives			= RendererMesh::PRIMITIVE_TRIANGLES;
	meshdesc.vertexBuffers		= &m_textVertexBuffer;
	meshdesc.numVertexBuffers	= 1;
	meshdesc.firstVertex		= 0;
	meshdesc.numVertices		= m_textVertexBuffer->getMaxVertices();
	meshdesc.indexBuffer		= m_textIndexBuffer;
	meshdesc.firstIndex			= 0;
	meshdesc.numIndices			= m_textIndexBuffer->getMaxIndices();
	meshdesc.instanceBuffer		= NULL;
	meshdesc.firstInstance		= 0;
	meshdesc.numInstances		= 0;
	m_textMesh = createMesh(meshdesc);
	RENDERER_ASSERT(m_textMesh, "Failed to create Mesh.");

    m_textMaterial = NULL;
    m_textVertexBufferOffset = 0;
    m_textIndexBufferOffset = 0;

    // create mesh for quad
	vbdesc.hint = RendererVertexBuffer::HINT_STATIC;
	vbdesc.maxVertices = 128;
	vbdesc.semanticFormats[RendererVertexBuffer::SEMANTIC_POSITION] = RendererVertexBuffer::FORMAT_FLOAT3;
	vbdesc.semanticFormats[RendererVertexBuffer::SEMANTIC_TEXCOORD0] = RendererVertexBuffer::FORMAT_FLOAT2;
	vbdesc.semanticFormats[RendererVertexBuffer::SEMANTIC_COLOR] = RendererVertexBuffer::FORMAT_COLOR_NATIVE;
	m_quadVertexBuffer = createVertexBuffer(vbdesc);
	RENDERER_ASSERT(m_quadVertexBuffer, "Failed to create Vertex Buffer.");
	// initialize index buffer
	inbdesc.hint = RendererIndexBuffer::HINT_STATIC;
	inbdesc.format = RendererIndexBuffer::FORMAT_UINT16;
	inbdesc.maxIndices = 128;
	m_quadIndexBuffer = createIndexBuffer(inbdesc);
	RENDERER_ASSERT(m_quadIndexBuffer, "Failed to create Instance Buffer.");
	meshdesc.primitives			= RendererMesh::PRIMITIVE_TRIANGLES;
	meshdesc.vertexBuffers		= &m_quadVertexBuffer;
	meshdesc.numVertexBuffers	= 1;
	meshdesc.firstVertex		= 0;
	meshdesc.numVertices		= m_quadVertexBuffer->getMaxVertices();
	meshdesc.indexBuffer		= m_quadIndexBuffer;
	meshdesc.firstIndex			= 0;
	meshdesc.numIndices			= m_quadIndexBuffer->getMaxIndices();
	meshdesc.instanceBuffer		= NULL;
	meshdesc.firstInstance		= 0;
	meshdesc.numInstances		= 0;
	m_quadMesh = createMesh(meshdesc);
	RENDERER_ASSERT(m_quadMesh, "Failed to create Mesh.");
}
Example #24
0
void fsExperiments::resize( ResizeEvent event )
{
	mArcball.setWindowSize( getWindowSize() );
	mArcball.setCenter( getWindowCenter() );
	mArcball.setRadius( 150 );
}
Example #25
0
void GraphicsEngine::drawGLTexture(GLuint textureID, float x, float y, int textureW, int textureH) {
	if (0 == textureID)
		return;

	Dimension2i size = getWindowSize();
	float w = (float)size.w, h = (float)size.h;

	if (x > w || y > h)
		return;

	GLuint textureVBO;
	glGenBuffers(1, &textureVBO);
	glBindBuffer(GL_ARRAY_BUFFER, textureVBO);

	GLfloat textureVertexData[] = {
		// X Y							U    V
		x, h - y - textureH, 0, 1.0f,
		x, h - y, 0, 0,
		x + textureW, h - y - textureH, 0.99f, 1.0f,

		x, h - y, 0, 0,
		x + textureW, h - y, 0.99f, 0,
		x + textureW, h - y - textureW, 0.99f, 1.0f
	};
	glBufferData(GL_ARRAY_BUFFER, sizeof(textureVertexData), textureVertexData, GL_STATIC_DRAW);

	GLuint shaderProgram = ShaderManager::getInstance()->getCurrentProgram();

	GLuint useTextureLocation = glGetUniformLocation(shaderProgram, "useTexture");
	GLuint useUI = glGetUniformLocation(shaderProgram, "useUI");

	glUseProgram(shaderProgram);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, textureID);
	glUniform1i(useTextureLocation, 1);

	glUniform1i(useUI, 1);

	// fast hack
	// TODO: make different shader prog for textures, or make autogenerated ones
	GLuint windowSizeLocation = glGetUniformLocation(shaderProgram, "windowSize");
	glUniform2f(windowSizeLocation, w / 2, h / 2);

	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);	// x,y repeat every 4 values

	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_TRUE, 4 * sizeof(GLfloat), (const GLvoid*)(2 * sizeof(GLfloat)));	// u,v start at 2, repeat 4

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glDrawArrays(GL_TRIANGLES, 0, 6);	// 2*3

	glDisable(GL_BLEND);

	// unbind everything
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindTexture(GL_TEXTURE_2D, 0);

	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);

	glUseProgram(0);

	glDeleteBuffers(1, &textureVBO);
}
Example #26
0
void LinuxEnvironment::setWindowResizable(bool resizable)
{
	setWindowResizableInt(resizable, getWindowSize());
}
Example #27
0
static void refreshLine(const char *prompt, struct current *current)
{
    int plen;
    int pchars;
    int backup = 0;
    int i;
    const char *buf = current->buf;
    int chars = current->chars;
    int pos = current->pos;
    int b;
    int ch;
    int n;
    int width;
    int bufwidth;

    /* Should intercept SIGWINCH. For now, just get the size every time */
    getWindowSize(current);

    plen = strlen(prompt);
    pchars = utf8_strwidth(prompt, utf8_strlen(prompt, plen));

    /* Scan the prompt for embedded ansi color control sequences and
     * discount them as characters/columns.
     */
    pchars -= countColorControlChars(prompt);

    /* Account for a line which is too long to fit in the window.
     * Note that control chars require an extra column
     */

    /* How many cols are required to the left of 'pos'?
     * The prompt, plus one extra for each control char
     */
    n = pchars + utf8_strwidth(buf, utf8_strlen(buf, current->len));
    b = 0;
    for (i = 0; i < pos; i++) {
        b += utf8_tounicode(buf + b, &ch);
        if (ch < ' ') {
            n++;
        }
    }

    /* Pluse one if the current char is a control character */
    if (current->pos < current->chars && get_char(current, current->pos) < ' ') {
        n++;
    }

    /* If too many are needed, strip chars off the front of 'buf'
     * until it fits. Note that if the current char is a control character,
     * we need one extra col.
     */
    while (n >= current->cols && pos > 0) {
        b = utf8_tounicode(buf, &ch);
        if (ch < ' ') {
            n--;
        }
        n -= utf8_width(ch);
        buf += b;
        pos--;
        chars--;
    }

    /* Cursor to left edge, then the prompt */
    cursorToLeft(current);
    outputChars(current, prompt, plen);

    /* Now the current buffer content */

    /* Need special handling for control characters.
     * If we hit 'cols', stop.
     */
    b = 0; /* unwritted bytes */
    n = 0; /* How many control chars were written */
    width = 0; /* current display width */
    bufwidth = utf8_strwidth(buf, pos);

    for (i = 0; i < chars; i++) {
        int ch;
        int w = utf8_tounicode(buf + b, &ch);
        if (ch < ' ') {
            n++;
        }

        width += utf8_width(ch);

        if (pchars + width + n >= current->cols) {
            break;
        }
        if (ch < ' ') {
            /* A control character, so write the buffer so far */
            outputChars(current, buf, b);
            buf += b + w;
            b = 0;
            outputControlChar(current, ch + '@');
            if (i < pos) {
                backup++;
            }
        }
        else {
            b += w;
        }
    }
    outputChars(current, buf, b);

    /* Erase to right, move cursor to original position */
    eraseEol(current);
    setCursorPos(current, bufwidth + pchars + backup);
}
void ofAppGLFWWindow::display(void){
	
	
	
	
	static ofEventArgs voidEventArgs;

	int width, height;

	width  = getWindowSize().x;
	height = getWindowSize().y;

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

	// I don't know why, I need more than one frame at the start in fullscreen mode
	// also, in non-fullscreen mode, windows/intel graphics, this bClearAuto just fails.
	// I seem to have 2 buffers, alot of flickering
	// and don't accumulate the way I expect.
	// with this line:   if ((bClearAuto == true) || nFrameCount < 3){
	// we do nFrameCount < 3, so that the buffers are cleared at the start of the app
	// or else we have video memory garbage to draw on to...

	//glDrawBuffer( GL_BACK );

	printf("nFrameCount %i \n", nFrameCount);
	
	 glDrawBuffer( GL_FRONT_AND_BACK );
	// glDrawBuffer( GL_FRONT );
	
	#ifdef TARGET_WIN32
		//windows doesn't get accumulation in window mode
		if ((bClearAuto == true || windowMode == OF_WINDOW) || nFrameCount < 3){
	#else
		//mac and linux does :)
		if ( bClearAuto == true || nFrameCount < 3){
	#endif
				glClearColor(bgPtr[0],bgPtr[1],bgPtr[2], bgPtr[3]);
			
		//	printf("clearing the screen \n");
			
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}

	if( bEnableSetupScreen )ofSetupScreen();

	if(ofAppPtr)
		ofAppPtr->draw();

	#ifdef OF_USING_POCO
		ofNotifyEvent( ofEvents().draw, voidEventArgs );
	#endif

	// Swap front and back buffers (we use a double buffered display)
    glfwSwapBuffers();

}


//------------------------------------------------------------
void ofAppGLFWWindow::exitApp(){
//	--  This is already happening in ofAppRunner

//	static ofEventArgs voidEventArgs;
//	if(ofAppPtr)ofAppPtr->exit();
//
//	#ifdef OF_USING_POCO
//		ofNotifyEvent( ofEvents().exit, voidEventArgs );
//	#endif

	ofLog(OF_LOG_VERBOSE,"GLFW app is being terminated!");

	// Terminate GLFW
	glfwTerminate();

	OF_EXIT_APP(0);
}
Example #29
0
void RenderQueue::flush()
{
    HGE *hge = hgeCreate(HGE_VERSION);
    const Point2f viewerPos = getViewerPos();
    const Rectf viewRange = getWindowViewer();
    const Rectf windowRange(0, getWindowSize().x, 0, getWindowSize().y);


    //Rect clip;
    //clip.leftTop = Point2s(100, 100);
    //clip.rightBottom = Point2s(200, 200);
    hge->Gfx_SetTransform();
    for (int i = MaxLayers - 1; i >= 0; --i)
    {
        vector<GfxObj> &go = gfxobjs[i];
        for (size_t j = 0; j < go.size(); ++j)
        {
            const GfxObj &obj = go[j];
            switch(obj.type)
            {
            case GfxObj::T_Anim:
                {
                    const GfxObj::Data::Anim &anim = obj.data.anim;

                    Point2f pos = gfxParams.getPoint2f(anim.iA);
                    if (!anim.screenPos)
                        pos -= viewerPos;
                    // FIXME: 100 is magic number, remove it by anim clip range
                    if (pos.x > windowRange.rightBottom.x + 100 || pos.x < windowRange.leftTop.x - 100 ||
                        pos.y < windowRange.leftTop.y - 100 || pos.y > windowRange.rightBottom.y + 100)
                        break;
                    //hge->Gfx_SetTransform();
                    hge->Gfx_SetTransform(0, 0, pos.x, pos.y, anim.direction/* - viewerOrientation*/, 1, 1);
                    anim.anim->render(anim.frame, 0);//&clip);
                    hge->Gfx_SetTransform();
                }
                break;
            case GfxObj::T_Line:
                {
                    const GfxObj::Data::Line &line = obj.data.line;

                    const Point2f &posA = gfxParams.getPoint2f(line.iA);
                    const Point2f &posB = gfxParams.getPoint2f(line.iB);
                    Rectf objRange(
                        min(posA.x, posB.x + .1f),
                        max(posA.x, posB.x + .1f),
                        min(posA.y, posB.y + .1f),
                        max(posA.y, posB.y + .1f));
                    if (line.screenPos)
                    {
                        Rectf x = objRange & windowRange;
                        if (x.Visible())
                        {
                            hge->Gfx_RenderLine(posA.x, posA.y,
                                posB.x, posB.y, line.color);
                        }
                    }
                    else
                    {
                        Rectf x = objRange & viewRange;
                        if (x.Visible())
                        {
                            hge->Gfx_RenderLine(posA.x - viewerPos.x, posA.y - viewerPos.y,
                                posB.x - viewerPos.x, posB.y - viewerPos.y, line.color);
                        }
                    }
                }
                break;
            case GfxObj::T_Text:
                {
                    const GfxObj::Data::Text &text = obj.data.text;
                    
                    Point2f posA = gfxParams.getPoint2f(text.iA);
                    if (!text.screenPos)
                    {
                        posA -= viewerPos;
                    }
                    posA = SnapNearestInteger(posA);
                    //text.font->Render(posA.x, posA.y, text.align, gfxParams.getString(text.iStr).c_str());
                    renderFontWithBk(*text.font, posA.x, posA.y, ~text.color & 0x00ffffff | 0x40000000, text.color, text.align, gfxParams.getString(text.iStr).c_str());

                }
                break;
            case GfxObj::T_Triple:
                {
                    const GfxObj::Data::Triple &triple = obj.data.triple;
                    const Point2f &posA = gfxParams.getPoint2f(triple.iA);
                    if (triple.screenPos)
                        hge->Gfx_SetTransform(0, 0, posA.x, posA.y, 0, 1, 1);
                    else
                        hge->Gfx_SetTransform(0, 0, posA.x - viewerPos.x, posA.y - viewerPos.y, 0, 1, 1);

                    hge->Gfx_RenderTriple(&gfxParams.getTriple(triple.iTriple));
                    hge->Gfx_SetTransform();
                }
                break;
            case GfxObj::T_Quad:
                {
                    const GfxObj::Data::Quad &quad = obj.data.quad;
                    hge->Gfx_RenderQuad(&gfxParams.getQuad(quad.iQuad));
                }
                break;
            }
        }
        go.clear();
    }
    hge->Gfx_SetTransform();
    hge->Release();
    gfxParams.clear();
}
Example #30
0
void LinuxEnvironment::disableFullscreen()
{
	if (!m_bFullScreen) return;

    // unsuggest fullscreen mode
	Atom atom = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", True);
	XChangeProperty(
		m_display, m_window,
		XInternAtom(m_display, "_NET_WM_STATE", True),
		XA_ATOM, 32, PropModeReplace,
		(unsigned char*)&atom, 1);

	// get identifiers for the provided atom name strings
	Atom wm_state = XInternAtom(m_display, "_NET_WM_STATE", False);
	Atom fullscreen = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False);

	XEvent xev;
	memset(&xev, 0, sizeof(xev));

	xev.type                 = ClientMessage;
	xev.xclient.window       = m_window;
	xev.xclient.message_type = wm_state;
	xev.xclient.format       = 32;
	xev.xclient.data.l[0]    = 0; // disable fullscreen (0 == false)
	xev.xclient.data.l[1]    = fullscreen;

	// send an event mask to the X-server
	XSendEvent(
		m_display,
		DefaultRootWindow(m_display),
		False,
		SubstructureNotifyMask,
		&xev);

	// enable window decorations
    Hints hints;
    Atom property;
    hints.flags = 2;
    hints.decorations = 1;
    property = XInternAtom(m_display, "_MOTIF_WM_HINTS", True);
    XChangeProperty(m_display, m_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);

	// restore previous size and position
    // NOTE: the y-position is not consistent, the window keeps going down when toggling fullscreen (probably due to decorations), force center() workaround
	XMoveResizeWindow(m_display,
			m_window,
			(int)m_vLastWindowPos.x,
			(int)m_vLastWindowPos.y,
			(unsigned int)m_vLastWindowSize.x,
			(unsigned int)m_vLastWindowSize.y);
	m_vResizeHackSize = m_vLastWindowSize;
	m_bResizeDelayHack = true;

	// update resizability with new resolution
	setWindowResizableInt(m_bFullscreenWasResizable, m_vLastWindowSize);

	center();

	m_vPrevDisableFullscreenWindowSize = getWindowSize();
	m_bFullScreen = false;
}