About Store Forum Documentation Contact
Donations:
140$/mo



Post Reply 
Rendering images in 3D, facing upwards
Author Message
mih Offline
Member

Post: #1
Rendering images in 3D, facing upwards
Hi, as in the title, i want to render image in 3d so it will be always facing up, something like decals but i want it to be in the air, is it possible ? or maybe it is possible to achive something similar using particles ?
thanks.
03-12-2010 06:55 PM
Find all posts by this user Quote this message in a reply
Panerox Offline
Member

Post: #2
RE: Rendering images in 3D, facing upwards
for example:
Code:
...
Image* image = ...;
Vtx3DSimple _A, _B, _C, _D;
_A.pos = Vec(-0.5, 0, -0.5);
_B.pos = Vec(0.5, 0, -0.5);
_C.pos = _Vec(0.5, 0, 0.5);
_D.pos = Vec(-0.5, 0, 0.5);    
_A.tex = Vec2(0,0);
_B.tex = Vec2(0,1);
_C.tex = Vec2(1,1);
_D.tex = Vec2(1,0);
...
switch (Renderer())
        {
        case RM_BLEND:
            {
            SetMatrix(<position + rotate + scale +...>);
            ALPHA_MODE alpha = D.alpha(ALPHA_BLEND_DEC);
            VI.image(image);
            VI.wrap();
            VI.face(_A, _B, _C, _D);
            VI.end();
            D.alpha(alpha);
            }
...
03-12-2010 07:43 PM
Find all posts by this user Quote this message in a reply
mih Offline
Member

Post: #3
RE: Rendering images in 3D, facing upwards
could you explain it little more ? You mean by using shaders or what ?
03-12-2010 08:03 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Rendering images in 3D, facing upwards
you can also use simple mesh (made from 2 triangles)
03-12-2010 09:00 PM
Find all posts by this user Quote this message in a reply
Panerox Offline
Member

Post: #5
RE: Rendering images in 3D, facing upwards
(03-12-2010 08:03 PM)mih Wrote:  could you explain it little more ? You mean by using shaders or what ?

no, not shaders.
i suggested to you that you can do this by using "VI - Vertex Index Buffer" (Vertex Index Buffer.h).
my example is even workingsmile
03-12-2010 09:28 PM
Find all posts by this user Quote this message in a reply
mih Offline
Member

Post: #6
RE: Rendering images in 3D, facing upwards
ok i'll give it a try, thanks smile
03-13-2010 08:24 AM
Find all posts by this user Quote this message in a reply
mih Offline
Member

Post: #7
RE: Rendering images in 3D, facing upwards
Finally I have found a time to try It, and I'm stuck pfft
Can someone direct me, what am I doing wrong ?
Here is how I was trying do to it :
As Panerox wrote these are the varibales :
Code:
Vtx3DSimple _A, _B, _C, _D;
Then in Init function I did that :
Code:
    _A.pos = Vec(-0.5, 0, -0.5);
    _B.pos = Vec(0.5, 0, -0.5);
    _C.pos = Vec(0.5, 0, 0.5);
    _D.pos = Vec(-0.5, 0, 0.5);  

    _A.tex = Vec2(0,0);
    _B.tex = Vec2(0,1);
    _C.tex = Vec2(1,1);
    _D.tex = Vec2(1,0);

    _A.nrm = Vec(0,1,0);
    _B.nrm = Vec(0,1,0);
    _C.nrm = Vec(0,1,0);
    _D.nrm = Vec(0,1,0);
and then In Draw function (I think I did something wrong here):
Code:
VI.image(Images("../data/logo+alpha.gfx"));
   VI.cull(true);
   VI.face(_A,_B,_C,_D);
   VI.end();
But the Image didn't show up, so any ideas wink ?
03-22-2010 07:21 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: Rendering images in 3D, facing upwards
try setting SetMatrix
try disabling culling for testing
03-22-2010 07:30 PM
Find all posts by this user Quote this message in a reply
mih Offline
Member

Post: #9
RE: Rendering images in 3D, facing upwards
Hm still nothing. That's how the whole code is looking like:
Code:
/******************************************************************************/
#include "stdafx.h"
/******************************************************************************/
Mesh mesh;
Vtx3DSimple _A, _B, _C, _D;

/******************************************************************************/
void InitPre()
{
   App.name("Rendering");
   App.flag=APP_MS_EXCLUSIVE;
   Paks.add("../data/engine.pak");
}
/******************************************************************************/
Bool Init()
{
   Cam.dist=2;

   mesh.create(1).base(0).create(Ball(1),VTX_TEX0|VTX_NRM|VTX_TNG);               // create Mesh with 1 MeshPart, and create this MeshPart's base from Ball with automatic texture coordinates, normals and tangents
   mesh.setMaterial(Materials("../data/mtrl/brick/0.mtrl")).setRender().setBox(); // set mesh material, rendering version and bounding box
    _A.pos = Vec(-0.5, 0, -0.5);
    _B.pos = Vec(0.5, 0, -0.5);
    _C.pos = Vec(0.5, 0, 0.5);
    _D.pos = Vec(-0.5, 0, 0.5);    
    _A.tex = Vec2(0,0);
    _B.tex = Vec2(0,1);
    _C.tex = Vec2(1,1);
    _D.tex = Vec2(1,0);
    _A.nrm = Vec(0,1,0);
    _B.nrm = Vec(0,1,0);
    _C.nrm = Vec(0,1,0);
    _D.nrm = Vec(0,1,0);

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   CamHandle(1.5,10,CAMH_ZOOM|CAMH_ROT);
   return true;
}
/******************************************************************************/
void Render() // Rendering Function
{
   switch(Renderer()) // Rendering Function will be called multiple times for different Rendering Modes
   {
      // the most important is the "prepare" mode in which you should draw all the meshes and add lights
      case RM_PREPARE:
      {
         // add directional light
         LightDir(Vec(0,0,1)).add();
      }break;
   }
}
void Draw()
{
   //D.clear(WHITE);
   Renderer(Render); // render with 'Render' function
   SetMatrix();
   VI.image(Images("../data/logo+alpha.gfx"));
   VI.face(_A,_B,_C,_D);
   VI.end();

   D.text(0,0.9,S+"Fps: "+Time.fps()); // show number of fps
}
/******************************************************************************/
Maybe ther's something else wrong with It ? (I just edited the first rendering tutorial)
03-22-2010 07:35 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
RE: Rendering images in 3D, facing upwards
you should set colors of vertexes
_A.color=WHITE;...
03-22-2010 07:57 PM
Find all posts by this user Quote this message in a reply
mih Offline
Member

Post: #11
RE: Rendering images in 3D, facing upwards
Didn't know that It has to be used too, thanks It's working now wink
03-22-2010 07:58 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
RE: Rendering images in 3D, facing upwards
if your codes they were set to transparent black (0) by default
03-22-2010 08:05 PM
Find all posts by this user Quote this message in a reply
Post Reply