write text to an texture

abtrakt

25-01-2012 21:03:48

Well hi, this is really spontaneous but I really need fast help

I was doing a BST representation in mogre using images with numbers.
For that i had to create the .jpg format images manually and put them in C:\MogreSDK\Media\materials\textures .

Now i need to rewrite the program to create the images while running, in other words, i dont want those images in materials folder, i want them to be created while the program is running to "improove" it... so every time a number is pulled and an object is created thets where i would like the image to be created.

This is how it works: it grabbs a number from a stack and it creates an object with the picture that has that number and well then comes the algorithm to make the tree.

I dont know how to create images from the code and thats where i need your help, i know its not hard and i would do it my self but i got eye surgery a few days ago do i shouldnt be using the computer and i need this for friday.

p.d. sorry for any wrong slepped words, english isnt my language.. the pictures are small, have a white background and a black number, numbers from 40-60
I'll leave the code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre;
using MOIS;
usi
namespace final
{
class Program : Example
{
int numLines = 0;
public override void CreateScene()
{
int[] valores = new int[10] { 50, 57, 59, 42, 44, 58, 56, 43, 40, 41 };
Plane p = new Plane(Mogre.Vector3.UNIT_Y, -10);
MeshManager.Singleton.CreatePlane("FloorPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, p, 200000F, 20000F, 20, 20, true, 1, 50F, 50F, Mogre.Vector3.UNIT_Z);

//Entity ent;

//ent = sceneMgr.CreateEntity("floor", "FloorPlane");
//ent.SetMaterialName("Examples/GrassFloor");
//sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

Light light = sceneMgr.CreateLight("Light1");
light.Type = Light.LightTypes.LT_DIRECTIONAL;
light.Direction = new Mogre.Vector3(1, -1, 0);

Nodo raiz = new Nodo(valores[0], sceneMgr);
sceneMgr.RootSceneNode.AddChild(raiz.getnodo());

raiz.getnodo().SetPosition(posX(raiz.getnum()), 300, 0);
float raizX = posX(raiz.getnum());

float posy = 50;
float posx = 80;
float levels = 1;
for (int i = 1; i < valores.Length; i++)
{
int valor = valores;
Nodo nuevo = new Nodo(valor, sceneMgr);
crearArbol(raiz, nuevo, posx, posy, levels, valores.Length, raizX);
}

//repara(raiz, levels);

}


public void crearArbol(Nodo raiz, Nodo nuevo, float posx, float posy, float levels, int size, float raizX)
{
if (raiz.getnum() > nuevo.getnum())
{

if (raiz.getizq() != null)
{
posx -= 20;
crearArbol(raiz.getizq(), nuevo, posx, posy, levels, size, raizX);
}
else
{
if (raiz.getder() == null)
{
levels++;
}

raiz.setizq(nuevo);
nuevo.getnodo().SetPosition((posX(nuevo.getnum()) - raiz.getposGlobal().x), -50, 0);
nuevo.setposGlobal(new Vector3(posX(nuevo.getnum()), raiz.getposGlobal().y + (-50), 0));
linea(raiz.getposGlobal().x + raizX, raiz.getposGlobal().y + 300, 0, nuevo.getposGlobal().x + raizX, nuevo.getposGlobal().y + 300, 0);
numLines++;
size--;
}
}
else if (raiz.getnum() < nuevo.getnum())
{
if (raiz.getder() != null)
{
posx -= 20;
crearArbol(raiz.getder(), nuevo, posx, posy, levels, size, raizX);
}
else
{
if (raiz.getizq() == null)
{
levels++;
}
raiz.setder(nuevo);
nuevo.getnodo().SetPosition((posX(nuevo.getnum()) - raiz.getposGlobal().x), -50, 0);
nuevo.setposGlobal(new Vector3(posX(nuevo.getnum()), raiz.getposGlobal().y + (-50), 0));
linea(raiz.getposGlobal().x + raizX, raiz.getposGlobal().y + 300, 0, nuevo.getposGlobal().x + raizX, nuevo.getposGlobal().y + 300, 0);
numLines++;
size--;
}

}

}
public float posX(int val)
{
float x = 0;
switch (val)
{
case 40:
x = -150;
break;
case 41:
x = -135;
break;
case 42:
x = -120;
break;
case 43:
x = -105;
break;
case 44:
x = -90;
break;
case 45:
x = -75;
break;
case 46:
x = -60;
break;
case 47:
x = -45;
break;
case 48:
x = -30;
break;
case 49:
x = -15;
break;
case 50:
x = 0;
break;
case 51:
x = 15;
break;
case 52:
x = 30;
break;
case 53:
x = 45;
break;
case 54:
x = 60;
break;
case 55:
x = 75;
break;
case 56:
x = 90;
break;
case 57:
x = 105;
break;
case 58:
x = 120;
break;
case 59:
x = 135;
break;
case 60:
x = 150;
break;
default:
x = 0;
break;
}
return x;
}
public void repara (Nodo raiz, float levels){

Stack <Nodo> der = new Stack <Nodo>();
Stack <Nodo> izk = new Stack <Nodo>();
Nodo nodo = raiz;
der.Push(raiz);

for(int i=0; i<levels; i++){

while(der.Peek()!=null){
Console.WriteLine("-----------------------------------------------");
izk.Push(der.Pop()); // >> inicialmente la cola contiene la raiz <<

}

while(izk.Peek()!=null){

nodo = izk.Pop();
nodo.getnodo().SetPosition(0,0,0);
nodo.setposGlobal(new Vector3((nodo.getposGlobal().x)*levels, nodo.getposGlobal().y, 0));
if(nodo.getizq() != null){
der.Push(nodo.getizq());
}
if(nodo.getder() != null){
der.Push(nodo.getder());
}

}
levels--;

}

}
static void Main(string[] args)
{
try
{
Program app = new Program();
app.Go();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.IsThrown)
Example.ShowOgreException();
else
throw;
}
}
public ManualObject linea(float x1, float y1, float z1, float x2, float y2, float z2)
{

ManualObject manual = sceneMgr.CreateManualObject("linea" + numLines);
manual.Begin("BaseWhiteNoLighting",
RenderOperation.OperationTypes.OT_LINE_LIST);

manual.Position(x1, y1, z1);
manual.TextureCoord(1, 1);
manual.Position(x2, y2, z2);
manual.TextureCoord(0, 0);

manual.Index(0);
manual.Index(1);

manual.End();

SceneNode lineNode;
lineNode = sceneMgr.RootSceneNode.CreateChildSceneNode("nodoLinea" + numLines);
lineNode.AttachObject(manual);

return manual;
}
}
}

namespace final
{
class Nodo
{
Vector3 posGlobal;
Nodo izq;
Nodo der;
int num;
SceneNode n;
SceneManager sceneMgr;
public Nodo(int num, SceneManager sceneMgr)
{
posGlobal = new Vector3(0, 0, 0);
izq = null;
der = null;
this.num = num;
this.sceneMgr = sceneMgr;
n = sceneMgr.CreateSceneNode("Nodo" + num);
n.AttachObject(crearNodo(num, n));


}


public ManualObject crearNodo(int num, SceneNode node)
{

MaterialPtr material = MaterialManager.Singleton.Create("DynMat" + num, // name
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
TextureUnitState thisTexture = material.GetTechnique(0).GetPass(0).CreateTextureUnitState(num + ".jpg");

Mogre.ManualObject manual = sceneMgr.CreateManualObject("grass" + num);
manual.Begin("DynMat" + num,
RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
// Triangulo 1
manual.Position(5, 0, 0);
manual.TextureCoord(1, 1);

manual.Position(5, 10, 0);
manual.TextureCoord(1, 0);

manual.Position(-5, 0, 0);
manual.TextureCoord(0, 1);

manual.Position(-5, 10, 0);
manual.TextureCoord(0, 0);


manual.Index(0);
manual.Index(1);
manual.Index(2);

manual.Index(1);
manual.Index(3);
manual.Index(2);
manual.End();

return manual;

}

public Nodo getizq()
{
return izq;
}
public void setizq(Nodo izquierdo)
{
this.izq = izquierdo;
this.n.AddChild(izquierdo.getnodo());
}
public Nodo getder()
{
return der;
}
public void setder(Nodo derecho)
{
this.der = derecho;
this.n.AddChild(derecho.getnodo());
}
public int getnum()
{
return num;
}
public void setnum(int numero)
{
this.num = numero;
}
public SceneNode getnodo()
{
return (n);
}
public Vector3 getposGlobal()
{
return posGlobal;
}
public void setposGlobal(Vector3 pos)
{
this.posGlobal = pos;
}
}

}ng Mogre.Demo.ExampleApplication;
using Vector3 = Mogre.Vector3;


Beauty

26-01-2012 19:30:10

Hi abtrakt,

nice to see that you use Mogre for a presentation.

First of all:
Please use "useful" subjects for forum topics.
Most of them could have the name "help please". It's not good for the overview.
You can use the edit button of your first post to change the title. (please do it)

Mogre has an API call to save the current frame to a file.
Unfortunately I can't look to my source code now. But maybe you can find it yourself by searching in this Mogre forum or Ogre main forum. Sometimes Google is a better alternative to search for something on the Ogre website. (use the addition "site:ogre3d.org" for your google search)

Well, what was your question?
Save Mogre images to a file or to load an image file to the Mogre resources?

The second case is possible - also on-the-fly. If you need code, I can have a look to my application.
Maybe I can do it today. But perhaps this needs some days.

abtrakt

27-01-2012 05:54:39

my question was how to create a texture with a label, on-the-fly.. not necessarely save it

Beauty

27-01-2012 11:45:46

OK, now I saw your new subject and know what you mean. 8)

Search for keywords like "rendering to texture" or "RTT".

Some useful links are here:

Intermediate Tutorial 7 - Render to texture (RTT)
MadMarx Tutorial 9 - Part 2 - Render A Texture To Itself
Ogre::RenderTexture Class Reference