generate basic text mesh, problem with texture
This commit is contained in:
parent
567651f687
commit
a2219c0982
@ -106,7 +106,7 @@ void Engine::setScene(SceneTree *scene)
|
|||||||
m_scene = scene;
|
m_scene = scene;
|
||||||
m_renderer->setScene(m_scene);
|
m_renderer->setScene(m_scene);
|
||||||
m_renderer->resizeGL(m_window->getSize().x, m_window->getSize().y);
|
m_renderer->resizeGL(m_window->getSize().x, m_window->getSize().y);
|
||||||
scene->addObject(scene->getRootObject(), m_sparrowshell);
|
// scene->addObject(scene->getRootObject(), m_sparrowshell);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::outputShell(std::string str)
|
void Engine::outputShell(std::string str)
|
||||||
|
@ -49,6 +49,11 @@ int main(){
|
|||||||
Font* fonte_des_neiges = Loader::loadFont("../data/consolas.fnt","../data/consolas.png");
|
Font* fonte_des_neiges = Loader::loadFont("../data/consolas.fnt","../data/consolas.png");
|
||||||
RESOURCE_ADD(fonte_des_neiges,Font,"shellfont");
|
RESOURCE_ADD(fonte_des_neiges,Font,"shellfont");
|
||||||
|
|
||||||
|
|
||||||
|
MeshNode* mnode = new MeshNode(fonte_des_neiges->getTextMesh("Hello World!"));
|
||||||
|
|
||||||
|
scene.addObject(scene.getRootObject(),mnode);
|
||||||
|
|
||||||
engine.setScene(&scene);
|
engine.setScene(&scene);
|
||||||
engine.start();
|
engine.start();
|
||||||
|
|
||||||
|
@ -1,6 +1,24 @@
|
|||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Font::Font()
|
Font::Font()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mesh* Font::getTextMesh(std::string s)
|
||||||
|
{
|
||||||
|
Mesh* text = new Mesh();
|
||||||
|
glm::vec2 current_pos(50,50);
|
||||||
|
for(auto carac : s){
|
||||||
|
CharInfo chinf = m_charTable[carac];
|
||||||
|
current_pos += chinf.offset;
|
||||||
|
text->addRectangle2D(current_pos,chinf.dim,chinf.pos,chinf.dim);
|
||||||
|
current_pos -= chinf.offset;
|
||||||
|
current_pos.x += (chinf.dim.x + chinf.offset.x);
|
||||||
|
}
|
||||||
|
text->setMaterial((Material*)m_mat);
|
||||||
|
text->setDepth(0.5);
|
||||||
|
text->initGL();
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
|
#include "mesh.h"
|
||||||
|
//#include "scenetree.h"
|
||||||
|
|
||||||
class PhongMaterial;
|
class PhongMaterial;
|
||||||
|
|
||||||
@ -11,9 +13,9 @@ class Font
|
|||||||
public:
|
public:
|
||||||
struct CharInfo
|
struct CharInfo
|
||||||
{
|
{
|
||||||
glm::vec2 pos;
|
glm::ivec2 pos;
|
||||||
glm::vec2 dim;
|
glm::ivec2 dim;
|
||||||
glm::vec2 offset;
|
glm::ivec2 offset;
|
||||||
int xadvance;
|
int xadvance;
|
||||||
};
|
};
|
||||||
Font();
|
Font();
|
||||||
@ -25,6 +27,7 @@ public:
|
|||||||
void setAntiAnliasing(bool antialiasing){m_antiAliasing = antialiasing;}
|
void setAntiAnliasing(bool antialiasing){m_antiAliasing = antialiasing;}
|
||||||
void setScale(glm::vec2 scale){m_scale = scale;}
|
void setScale(glm::vec2 scale){m_scale = scale;}
|
||||||
void setMaterial(PhongMaterial *mat){m_mat = mat;}
|
void setMaterial(PhongMaterial *mat){m_mat = mat;}
|
||||||
|
Mesh* getTextMesh(std::string s);
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
PhongMaterial *m_mat;
|
PhongMaterial *m_mat;
|
||||||
|
@ -96,12 +96,12 @@ Font* Loader::loadFont(const std::string &description_file, const std::string &t
|
|||||||
font->addCharInfo(id,char_info);
|
font->addCharInfo(id,char_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Parsing finished" << std::endl;
|
|
||||||
Image* fucking_image_of_doom = loadImage(texture_file);
|
Image* fucking_image_of_doom = loadImage(texture_file);
|
||||||
Texture* texture = new Texture(fucking_image_of_doom);
|
Texture* texture = new Texture(fucking_image_of_doom);
|
||||||
delete fucking_image_of_doom;
|
delete fucking_image_of_doom;
|
||||||
PhongMaterial* mat = new PhongMaterial();
|
PhongMaterial* mat = new PhongMaterial();
|
||||||
mat->setTexture(PhongMaterial::DIFFUSE_SLOT,texture,font_name);
|
mat->setTexture(PhongMaterial::DIFFUSE_SLOT,texture,font_name);
|
||||||
|
// mat->diffuse = glm::vec3(1,1,1);
|
||||||
font->setMaterial(mat);
|
font->setMaterial(mat);
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user