示例#1
0
    // Render the given string, updating x and y to the point where the next character
    // after this string should be placed.
    void Graphics::RenderTextUpdatePos(const FontAsset& font, const std::wstring& text, float *x, float *y)
    {
        Rect verts, texCoords;

        BindFont(&font);

        glBegin(GL_QUADS);
        for (int i = 0; i < text.size(); i++)
        {
            // Render any non-control characters
            int unicodeCodepoint = text[i];
            if (unicodeCodepoint >= 32)
            {
				font.GetGlyphData(unicodeCodepoint, x, y, verts, texCoords);
                
				glTexCoord2f(texCoords.topLeft.x, texCoords.topLeft.y);
				glVertex2f(verts.topLeft.x, verts.topLeft.y);
                
				glTexCoord2f(texCoords.bottomRight.x, texCoords.topLeft.y);
				glVertex2f(verts.bottomRight.x, verts.topLeft.y);
                
				glTexCoord2f(texCoords.bottomRight.x, texCoords.bottomRight.y);
				glVertex2f(verts.bottomRight.x, verts.bottomRight.y);
                
				glTexCoord2f(texCoords.topLeft.x, texCoords.bottomRight.y);
				glVertex2f(verts.topLeft.x, verts.bottomRight.y);
            }
        }
        glEnd();
    }
SimpleOpenGL3App::SimpleOpenGL3App(	const char* title, int width,int height)
{
	gApp = this;
	m_data = new SimpleInternalData;
	m_window = new b3gDefaultOpenGLWindow();
	b3gWindowConstructionInfo ci;
	ci.m_title = title;
	ci.m_width = width;
	ci.m_height = height;
	m_window->createWindow(ci);
	
	m_window->setWindowTitle(title);
	glClearColor(1,1,1,1);
	m_window->startRendering();
#ifndef __APPLE__
	glewInit();
#endif

	m_primRenderer = new GLPrimitiveRenderer(width,height);
	
	m_instancingRenderer = new GLInstancingRenderer(128*1024,4*1024*1024);
	m_instancingRenderer->init();
	m_instancingRenderer->resize(width,height);
	m_instancingRenderer->InitShaders();

	m_window->setMouseMoveCallback(b3DefaultMouseMoveCallback);
	m_window->setMouseButtonCallback(b3DefaultMouseButtonCallback);
	m_window->setKeyboardCallback(b3DefaultKeyboardCallback);
	m_window->setWheelCallback(b3DefaultWheelCallback);
	m_window->setResizeCallback(SimpleResizeCallback);

	TwGenerateDefaultFonts();
	m_data->m_fontTextureId = BindFont(g_DefaultNormalFont);
}
示例#3
0
    // Render the given string, updating x and y to the point where the next character
    // after this string should be placed.
    void Graphics::RenderTextUpdatePos(const FontAsset& font, const std::string& text, float *x, float *y)
    {
        Rect verts, texCoords;
        
        BindFont(&font);
        
        glBegin(GL_QUADS);
        for (int i = 0; i < text.size(); i++)
        {
            char c = text[i];
            if ((c >= 32) && (c < 128))
            {
				font.GetGlyphData((int)c, x, y, verts, texCoords);
                
				glTexCoord2f(texCoords.topLeft.x, texCoords.topLeft.y);
				glVertex2f(verts.topLeft.x, verts.topLeft.y);
                
				glTexCoord2f(texCoords.bottomRight.x, texCoords.topLeft.y);
				glVertex2f(verts.bottomRight.x, verts.topLeft.y);
                
				glTexCoord2f(texCoords.bottomRight.x, texCoords.bottomRight.y);
				glVertex2f(verts.bottomRight.x, verts.bottomRight.y);
                
				glTexCoord2f(texCoords.topLeft.x, texCoords.bottomRight.y);
				glVertex2f(verts.topLeft.x, verts.bottomRight.y);
            }
        }
        glEnd();
    }
示例#4
0
SimpleOpenGL3App::SimpleOpenGL3App(	const char* title, int width,int height)
{
	gApp = this;
	m_data = new SimpleInternalData;
	m_window = new b3gDefaultOpenGLWindow();
	b3gWindowConstructionInfo ci;
	ci.m_title = title;
	ci.m_width = width;
	ci.m_height = height;
	m_window->createWindow(ci);
	
	m_window->setWindowTitle(title);
	glClearColor(1,1,1,1);
	m_window->startRendering();
#ifndef __APPLE__
	glewInit();
#endif

	m_primRenderer = new GLPrimitiveRenderer(width,height);
	
	m_instancingRenderer = new GLInstancingRenderer(128*1024,4*1024*1024);
	m_instancingRenderer->init();
	m_instancingRenderer->resize(width,height);
	m_instancingRenderer->InitShaders();

	m_window->setMouseMoveCallback(b3DefaultMouseMoveCallback);
	m_window->setMouseButtonCallback(b3DefaultMouseButtonCallback);
	m_window->setKeyboardCallback(b3DefaultKeyboardCallback);
	m_window->setWheelCallback(b3DefaultWheelCallback);
	m_window->setResizeCallback(SimpleResizeCallback);

	TwGenerateDefaultFonts();
	m_data->m_fontTextureId = BindFont(g_DefaultNormalFont);


	{
		GLint err;
	
	int datasize;

	float sx,sy,dx,dy,lh;
	GLuint texture;
	m_data->m_renderCallbacks = new OpenGL2RenderCallbacks(m_primRenderer);
	m_data->m_fontStash = sth_create(512,512,m_data->m_renderCallbacks);//256,256);//,1024);//512,512);
    err = glGetError();
    assert(err==GL_NO_ERROR);

	if (!m_data->m_fontStash)
	{
		b3Warning("Could not create stash");
		//fprintf(stderr, "Could not create stash.\n");
	}
	int droidRegular=0;

	char* data2 = OpenSansData;
	unsigned char* data = (unsigned char*) data2;
	if (!(m_data->m_droidRegular = sth_add_font_from_memory(m_data->m_fontStash, data)))
	{
		b3Warning("error!\n");
	}
    err = glGetError();
    assert(err==GL_NO_ERROR);
	}
}
示例#5
0
SimpleOpenGL3App::SimpleOpenGL3App(	const char* title, int width,int height)
{
	gApp = this;
	m_data = new SimpleInternalData;
	m_data->m_frameDumpPngFileName = 0;
	m_data->m_renderTexture = 0;
	m_data->m_ffmpegFile = 0;
	m_data->m_userPointer = 0;

	m_window = new b3gDefaultOpenGLWindow();
	b3gWindowConstructionInfo ci;
	ci.m_title = title;
	ci.m_width = width;
	ci.m_height = height;
	m_window->createWindow(ci);

	m_window->setWindowTitle(title);

	 b3Assert(glGetError() ==GL_NO_ERROR);

	glClearColor(0.9,0.9,1,1);
	m_window->startRendering();
	b3Assert(glGetError() ==GL_NO_ERROR);

#ifndef __APPLE__
#ifndef _WIN32
//some Linux implementations need the 'glewExperimental' to be true
    glewExperimental = GL_TRUE;
#endif


    if (glewInit() != GLEW_OK)
        exit(1); // or handle the error in a nicer way
    if (!GLEW_VERSION_2_1)  // check that the machine supports the 2.1 API.
        exit(1); // or handle the error in a nicer way

#endif
    glGetError();//don't remove this call, it is needed for Ubuntu

    b3Assert(glGetError() ==GL_NO_ERROR);

	m_primRenderer = new GLPrimitiveRenderer(width,height);
	m_parameterInterface = 0;

    b3Assert(glGetError() ==GL_NO_ERROR);

	m_instancingRenderer = new GLInstancingRenderer(128*1024,4*1024*1024);
	m_instancingRenderer->init();
	m_instancingRenderer->resize(width,height);

	b3Assert(glGetError() ==GL_NO_ERROR);

	m_instancingRenderer->InitShaders();

	m_window->setMouseMoveCallback(b3DefaultMouseMoveCallback);
	m_window->setMouseButtonCallback(b3DefaultMouseButtonCallback);
	m_window->setKeyboardCallback(b3DefaultKeyboardCallback);
	m_window->setWheelCallback(b3DefaultWheelCallback);
	m_window->setResizeCallback(SimpleResizeCallback);

	TwGenerateDefaultFonts();
	m_data->m_fontTextureId = BindFont(g_DefaultNormalFont);


	{



	m_data->m_renderCallbacks = new OpenGL2RenderCallbacks(m_primRenderer);
	m_data->m_fontStash = sth_create(512,512,m_data->m_renderCallbacks);//256,256);//,1024);//512,512);
    b3Assert(glGetError() ==GL_NO_ERROR);

	if (!m_data->m_fontStash)
	{
		b3Warning("Could not create stash");
		//fprintf(stderr, "Could not create stash.\n");
	}


	char* data2 = OpenSansData;
	unsigned char* data = (unsigned char*) data2;
	if (!(m_data->m_droidRegular = sth_add_font_from_memory(m_data->m_fontStash, data)))
	{
		b3Warning("error!\n");
	}
    b3Assert(glGetError() ==GL_NO_ERROR);
	}
}