generate basic text mesh, problem with texture
This commit is contained in:
parent
567651f687
commit
a2219c0982
src
@ -106,7 +106,7 @@ void Engine::setScene(SceneTree *scene)
|
||||
m_scene = scene;
|
||||
m_renderer->setScene(m_scene);
|
||||
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)
|
||||
|
@ -49,6 +49,11 @@ int main(){
|
||||
Font* fonte_des_neiges = Loader::loadFont("../data/consolas.fnt","../data/consolas.png");
|
||||
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.start();
|
||||
|
||||
|
@ -1,6 +1,24 @@
|
||||
#include "font.h"
|
||||
#include <iostream>
|
||||
|
||||
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 <glm/vec2.hpp>
|
||||
#include "mesh.h"
|
||||
//#include "scenetree.h"
|
||||
|
||||
class PhongMaterial;
|
||||
|
||||
@ -11,9 +13,9 @@ class Font
|
||||
public:
|
||||
struct CharInfo
|
||||
{
|
||||
glm::vec2 pos;
|
||||
glm::vec2 dim;
|
||||
glm::vec2 offset;
|
||||
glm::ivec2 pos;
|
||||
glm::ivec2 dim;
|
||||
glm::ivec2 offset;
|
||||
int xadvance;
|
||||
};
|
||||
Font();
|
||||
@ -24,10 +26,11 @@ public:
|
||||
void setBase(int base){m_base = base;}
|
||||
void setAntiAnliasing(bool antialiasing){m_antiAliasing = antialiasing;}
|
||||
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:
|
||||
std::string m_name;
|
||||
PhongMaterial* m_mat;
|
||||
PhongMaterial *m_mat;
|
||||
std::map<wchar_t,CharInfo> m_charTable;
|
||||
glm::vec2 m_scale;
|
||||
bool m_antiAliasing;
|
||||
|
@ -96,12 +96,12 @@ Font* Loader::loadFont(const std::string &description_file, const std::string &t
|
||||
font->addCharInfo(id,char_info);
|
||||
}
|
||||
|
||||
std::cout << "Parsing finished" << std::endl;
|
||||
Image* fucking_image_of_doom = loadImage(texture_file);
|
||||
Texture* texture = new Texture(fucking_image_of_doom);
|
||||
delete fucking_image_of_doom;
|
||||
PhongMaterial* mat = new PhongMaterial();
|
||||
mat->setTexture(PhongMaterial::DIFFUSE_SLOT,texture,font_name);
|
||||
// mat->diffuse = glm::vec3(1,1,1);
|
||||
font->setMaterial(mat);
|
||||
return font;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user