예제 #1
0
파일: main.cpp 프로젝트: knyazsergei/lab7
int main()
{
	sf::ContextSettings settings;
	settings.antialiasingLevel = 8;

	sf::RenderWindow window(sf::VideoMode(800, 600), "Lab7", sf::Style::Default, settings);
	sf::View view = sf::View(sf::FloatRect(0, 0, float(window.getSize().x), float(window.getSize().y)));
	window.setView(view);
	window.setVerticalSyncEnabled(true);

	sf::Clock clock;
	
	//init some objects
	struct tm time = getTime();
	struct vectorObjects shapes = initVectorObjects();
	sf::Vector2f center = getCenter(window);
	sf::Text text = initText("rubik.ttf");
	resize(window, shapes);
	setFirstPosition(shapes);

	while (window.isOpen())
	{
		sf::Time elapsed = clock.restart();
		animationUpdate(elapsed, shapes);

		drawWindows(window, shapes, text);

		window.display();
		events(window, shapes);
	}

	return 0;
}
예제 #2
0
void Live2dXSprite::draw()
{
    if(!m_pobTexture)
    {
        return;
    }
    if(m_isAnimation)
    {
        cc_timeval nowTime;
        CCTime::gettimeofdayCocos2d(&nowTime, NULL);
        float deltime = (float)(nowTime.tv_sec - m_nowTime.tv_sec) + (float)(nowTime.tv_usec - m_nowTime.tv_usec)/1000000.0f;
        m_nowTime = nowTime;
        animationUpdate(deltime);
//        animationUpdate(1/30.0f);
    }
#define Live2dX_Vertex_Size sizeof(Live2dX_Vertex)
#define Live2dX_UV_Size sizeof(Live2dX_UV)
#define Live2dX_Color_Size sizeof(Live2dX_Color)
    
#ifndef __QT__
    CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
    
    CCAssert(!m_pobBatchNode, "If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called");
    
    CC_NODE_DRAW_SETUP();
    
    ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );
    
    ccGLBindTexture2D( m_pobTexture->getName() );
    ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );

    
    // vertex
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, Live2dX_Vertex_Size, (void*)m_nowVertex.data());
    
    // texCoods
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, Live2dX_UV_Size, (void*)m_orginUV.data());
    
    // color
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, Live2dX_Color_Size, (void*)m_orginColor.data());
    
    
    glDrawArrays(GL_TRIANGLES, 0, (int)m_nowVertex.size());
    
    CHECK_GL_ERROR_DEBUG();
    
    CC_INCREMENT_GL_DRAWS(1);
    
    CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
#else
    
    glTranslatef(-0.5f,0,0);
    glEnable(GL_BLEND);
    
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glBindTexture(GL_TEXTURE_2D,m_pobTexture->m_name);
    
    for(int i = 0; i < m_nowVertex.size();i+=3)
    {
        float a,b;
        glBegin(GL_TRIANGLES);
        glColor4f(1,1,1,1);
        glTexCoord2f(m_orginUV[i].u,1-m_orginUV[i].v);
        a = m_nowVertex[i].x * 2 / m_baseSize.width - 1;
        b = m_nowVertex[i].y * 2 / m_baseSize.height-1;
        glVertex3f(a,b,0);
        glColor4f(1,1,1,1);
        glTexCoord2f(m_orginUV[i+1].u,1-m_orginUV[i+1].v);
        a = m_nowVertex[i+1].x * 2 / m_baseSize.width - 1;
        b = m_nowVertex[i+1].y * 2 / m_baseSize.height-1;
        glVertex3f(a,b,0);
        glColor4f(1,1,1,1);
        glTexCoord2f(m_orginUV[i+2].u,1-m_orginUV[i+2].v);
        a = m_nowVertex[i+2].x * 2 / m_baseSize.width - 1;
        b = m_nowVertex[i+2].y * 2 / m_baseSize.height-1;
        glVertex3f(a,b,0);
        glColor4f(1,1,1,1);
        glEnd();
    }
#endif
}