Forums Gallery LOGIN |REGISTER

Community Archive is read-only - Here you can view content recorded up until February 2017. To join the latest discussions visit our new forums


New Viewport + RENDER TO TEXTURE

Please use this forum for questions on C++, Lua, XML, and any other languages used in Crysis modding.


 

User avatar Blue
Junior Dev
Junior Dev
 
Posts: 328
Member since: 18.02.2009, 10:55
Likes: 22

Postby Blue » 04.01.2011, 20:07

if you are busy atm , if you send me code (pm) I can easily make flownodes , with your credits of course


I also used a FlowNode, all what you need to create a second viewport is posted here in the thread. The FG Plugins ill create are for those who cant programm. All who can (& cant wait ^^) shall find the things to do it here in the thread (jveer & z_kaiser have done it in the blink of an eye :happy: ).

To the code, its funny, but ive answerd this question on the first page of this thread: :cheesy:

To the point with the entire source code:

The code was only for trying to accomplish more viewports, so ive changed it a lot. Last point was to create some virtual material for objects. So i asked here in the forum if someone knows how i can allocate a texture per code to a material, but sadly, no one has answerd. ;( As i said before, ive tryed the hole stuff two weeks, so i messed up the code and thats the reson i havent posted it here.

If you have problems to make a second view port even with the code snippets ive posted before, i think you wont be happy with my code,
because he is like a ground zero in the programming world. :happy:



Blue
User avatar Mr.Hankey
Regular Dev
Regular Dev
 
Posts: 476
Member since: 06.11.2007, 20:41
Location: Germany
Likes: 0

Postby Mr.Hankey » 04.01.2011, 21:38

I'm still trying to figure out how you actually constructed a texture that i can use e.g for Draw2dImage.
While i get an unsinged int array from ReadFrameBufferFast any texture creating function i could find seems to only take unsigned char arrays...
User avatar Blue
Junior Dev
Junior Dev
 
Posts: 328
Member since: 18.02.2009, 10:55
Likes: 22

Postby Blue » 05.01.2011, 15:36

Hi, its realy easy, you only must make a reinterpret cast.

As you see:
Unsigned Integer == 32 bit
Unsigned Char == 8 bit

The ReadFramebufferFast gives you ARGB data -> for each caracter you need 8 bit (4x8bit == 32 bit). So it fills it in a unsigned integer - but it could also do it with a unsigned char[4].

To store the normal ReadFramebuffer data you need a unsigned char array : (Hight*Width)*4. So it is using also a size of 32 bit per pixel.

As you can see, they store both the same - thats the reason why you can use a reinterpret cast to switch your array to the type you need.

Its realy unlogic that they used two types (unsigned char/int) but they have. :happy:


greetings, Blue
User avatar Jonzki1
Skilled Developer
Skilled Developer
 
Posts: 662
Member since: 11.07.2008, 12:34
Location: Finland
Likes: 0

Postby Jonzki1 » 05.01.2011, 21:50

I've kept a close eye on this thread, great work! :) Can you draw the secondary viewport onto the screen, so that one could for example have a camera follow him and show what happens behind his back?
If there's an exception to every rule, there must be an exception to the rule that there's an exception to every rule. How about that?
User avatar Blue
Junior Dev
Junior Dev
 
Posts: 328
Member since: 18.02.2009, 10:55
Likes: 22

Postby Blue » 07.01.2011, 18:58

Originally posted by Jonzki1
I've kept a close eye on this thread, great work! :) Can you draw the secondary viewport onto the screen, so that one could for example have a camera follow him and show what happens behind his back?


Ups, sry havent seen this. To the question: yes you can. ;)

Blue
User avatar DURLI
Regular Dev
Regular Dev
 
Posts: 545
Images: 2
Member since: 21.10.2009, 19:52
Location: Slovakia, EU
Likes: 6

Postby DURLI » 09.01.2011, 13:20

I still can't understand how to use output from ReadBufferFast to Draw2Dimage. Can you explain more detail please?
Image
C++ || C# || 3D Artist || 2D Artist || UI Artist || Animator
User avatar Blue
Junior Dev
Junior Dev
 
Posts: 328
Member since: 18.02.2009, 10:55
Likes: 22

Postby Blue » 09.01.2011, 18:58

hope ive understood you right.

let your node inherit from hudobject
then use the update from it to draw the image

that is because the hud is the highest (or lowest ?( :happy: ) layer. so you can show your picture on the screen.


hope that helps,

blue
User avatar DURLI
Regular Dev
Regular Dev
 
Posts: 545
Images: 2
Member since: 21.10.2009, 19:52
Location: Slovakia, EU
Likes: 6

Postby DURLI » 09.01.2011, 19:32

well, i didn´t mean that at all.
I wanna use Draw2Dimage from pRenderer, but dunno how to use output from ReadBufferFast ( ARGB unsigned int) with it . Thanks
Image
C++ || C# || 3D Artist || 2D Artist || UI Artist || Animator
User avatar Mr.Hankey
Regular Dev
Regular Dev
 
Posts: 476
Member since: 06.11.2007, 20:41
Location: Germany
Likes: 0

Postby Mr.Hankey » 09.01.2011, 19:48

I guess DURLI and me need some hardcore spoonfeeding here :D

So this is basically what i got (placed in the CPlayer::Update function)
Code: Select all
    IRenderer* pRenderer = gEnv->pRenderer;
    unsigned int uTexSource[(800*600)*4];

    CCamera camOrigin = gEnv->pSystem->GetViewCamera(); //first save the curren camera
    m_scopeCamera = camOrigin;
    m_scopeCamera.SetAngles(Ang3(0,0,0));
    gEnv->pSystem->RenderBegin(); //let the framework know that it will start with the rendering
    pRenderer->SetCamera(m_scopeCamera); //set a new cam
    gEnv->p3DEngine->RenderWorld(pRenderer->GetRenderType(), pRenderer->GetCamera(), "cam_try1", -1, FILTER_LINEAR ); //render the world to the framebuffer
    pRenderer->ReadFrameBufferFast(uTexSource,  800, 600); //read the framebuffer
    pRenderer->SetCamera(camOrigin); //dosnt know if its nexessary - for some reason ive deactivated it... the code is full of changes because of try and error ^^
    gEnv->pSystem->RenderBegin(); //let the framework know that it can do what it want to do ^^

    int tex = pRenderer->SF_CreateTexture(800, 600, 0, reinterpret_cast<unsigned char*>(uTexSource), eTF_A8R8G8B8);
    pRenderer->Draw2dImage(500.f, 500.f, 800.f, 600.f, tex);
But apparently all this does is drop my FPS from 100+ to 8 and create a really weird radial blur all over the screen.
User avatar Blue
Junior Dev
Junior Dev
 
Posts: 328
Member since: 18.02.2009, 10:55
Likes: 22

Postby Blue » 10.01.2011, 01:55

THIS POST WAS EDITED

@durli

I wanna use Draw2Dimage from pRenderer, but dunno how to use output from ReadBufferFast ( ARGB unsigned int) with it . Thanks


Ah, hm ok - the info from readframebufferfast is only a bitfield with the informations, you must create a texture. Im not on my laptop - thats because im this week not at home (... but my laptop :whistle: ), so sry i cant help you with looking in my code.

This is from Mr.Hankey:EDIT
Code: Select all
int tex = pRenderer->SF_CreateTexture(800, 600, 0, reinterpret_cast<unsigned char*>(uTexSource), eTF_A8R8G8B8);


- the "tex" integer holdes the id of the texture.
- the "&" gives the address of the array - thats necessary if you dont create the array like this:
EDIT: Sry, dont listen to crap ive wrote so late that my mind fools my selfe, the "&" would necessary if you refere to a special position in the array like uTexSource[3]


Code: Select all
unsigned int * uTexSourced = new unsigned int[800x600];


After creating or updating the texture - you must youse the texture id in the draw2image function like mr.hanky has done.

---------------------------------------------------------------------------

@Mr.Hankey

I dosnt know if the cplayer::update function has the right "position" in the queue - you could try to make a node where you inheriate from frameobject - after registrating the node like a listener, you can draw the image in the inheriat hudobject::update to the screen.

Second ive found is this:
Code: Select all
unsigned int uTexSource[(800*600)*4];


This is wrong because the *4 is if you use the ReadFramebuffer function - here you need a unsigned char array -> char == 8bit >> ARGB 4 x 1 char -> a unsigned int has normaly with the current os 32 bit.

To this point:
Code: Select all
m_scopeCamera.SetAngles(Ang3(0,0,0));


If i remember right, the setangels dosnt work... right. Sry cant be specific because i only remember that there where some problems with this. Perhaps you should try to comment it out and try first .setPos(vec3(50.0f, 50.0f, 50.0f)) - so it wouldnt draw your view in the texture and you can check where the errors are.

Here...
EDIT
Code: Select all
int tex = pRenderer->SF_CreateTexture(800, 600, 0, reinterpret_cast<unsigned char*>(uTexSource), eTF_A8R8G8B8);


... you create all the time a new texture (if im right), perhaps you should update the created texture in the buffer - there is some function who can do this in the renderer (updatetexture or updatevideobuffer or something like this).

-> Ive insered a "&" in your code - thats because you need a pointer in this function - with the "&" "tag" (sry my bad english) you get the memory address (its more or less the same as a pointer - the difference is that if you use "unsigned int * pointer = new unsigned int" its on the heap - in your way its on the stack. But a pointer holdes the address of the alocated memory - to get it from a variable who is on the stack - you need "&").
EDIT: Sry, dont listen to crap ive wrote so late that my mind fools my selfe, the "&" would necessary if you refere to a special position in the array like uTexSource[3]

But apparently all this does is drop my FPS from 100+ to 8 and create a really weird radial blur all over the screen.


Youll get a realy high framedrop - but 8 is realy a little bit low. The "weird radial blue" is a sign that you do something - but you doesnt do it right. So it is bad - but actually its good because it shows you that you are on the right way. ;)

-------------------------------------------------------------------

So friends, hope i could help you (especially durly, sry that ive understood you right at the first time). If there are more questions, or if it dosnt work, post again, ill try to help you so good as i can. Please excuse my bad english.


Blue

-------------------------------------------------------------------

EDIT:
Why no one loughs about me or correct the bullshit i wrote yesterday? :puppy: Good that i had the feeling that ive posted something wrong yesterday and looked today again in it - im realy sorry.

Blue
Last edited by Blue on 10.01.2011, 19:05, edited 7 times in total.
User avatar jagdaniel
Just getting started
Just getting started
 
Posts: 1
Member since: 13.01.2011, 11:25
Likes: 0

Postby jagdaniel » 13.01.2011, 11:48

Here's my working code:

HUD.h:
private:
CCamera m_CameraN;
Vec3 m_vecCamPosition;
int m_renderTargetN;

HUD.cpp:
bool CHUD::Init():
m_renderTargetN = gEnv->pRenderer->CreateRenderTarget(1048, 768, eTF_A8R8G8B8);

CHUD::~CHUD():
gEnv->pRenderer->DestroyRenderTarget(m_renderTargetN);

void CHUD::OnPostUpdate(float frameTime):
float fov = 73.7398*gf_PI/180.0f;
IActor * pActor = g_pGame->GetIGameFramework()->GetClientActor();
Vec3 actorPos = pActor->GetEntity()->GetPos();
m_vecCamPosition = actorPos;
m_vecCamPosition.z += 1.9f;
m_CameraN.SetFrustum(1024,768,fov);
m_CameraN.SetMatrix(m_CameraN.CreateOrientationYPR(Ang3(-gf_PI*0.5f,0.0f,0.0f)));
m_CameraN.SetPosition(m_vecCamPosition);
gEnv->pRenderer->SetRenderTarget(m_renderTargetN);
gEnv->pRenderer->BeginFrame();
gEnv->p3DEngine->RenderWorld(gEnv->pRenderer->GetRenderType() | SHDF_ALLOW_WATER, m_CameraN, "cam_tryN");
gEnv->pRenderer->SetRenderTarget(0);
gEnv->pRenderer->Draw2dImage(0,0,400,300,m_renderTargetN,1,0,0,1,180,1,1,1,1,1);

My question is if anyone has an idéa of how to set an assymetric frustum. I cannot get cry_camera modifications to work.

/Daniel
User avatar DURLI
Regular Dev
Regular Dev
 
Posts: 545
Images: 2
Member since: 21.10.2009, 19:52
Location: Slovakia, EU
Likes: 6

Postby DURLI » 15.01.2011, 16:10

hi, jagdaniel,
thank you for posting your code !
Last edited by DURLI on 15.01.2011, 17:50, edited 1 time in total.
Image
C++ || C# || 3D Artist || 2D Artist || UI Artist || Animator
User avatar DURLI
Regular Dev
Regular Dev
 
Posts: 545
Images: 2
Member since: 21.10.2009, 19:52
Location: Slovakia, EU
Likes: 6

Postby DURLI » 16.01.2011, 10:52

Im also trying to get FlowNode to work, but Im still getting very strange, blurred screen, without lot of models.
check my flownode code here


Image
Image
C++ || C# || 3D Artist || 2D Artist || UI Artist || Animator
User avatar DURLI
Regular Dev
Regular Dev
 
Posts: 545
Images: 2
Member since: 21.10.2009, 19:52
Location: Slovakia, EU
Likes: 6

Postby DURLI » 17.01.2011, 20:51

so I managed to get RenderToViewport working.

Image
Image
C++ || C# || 3D Artist || 2D Artist || UI Artist || Animator
User avatar Mr.Hankey
Regular Dev
Regular Dev
 
Posts: 476
Member since: 06.11.2007, 20:41
Location: Germany
Likes: 0

Postby Mr.Hankey » 17.01.2011, 23:02

Grrr why do you guys always leave out the code related stuff as soon as you achieve something? :D

Anyways this is my code...
Code: Select all
    float fov = DEG2RAD(50);
    CPlayer * pPlayer = static_cast<CPlayer*>( g_pGame->GetIGameFramework()->GetClientActor());
    Matrix34 viewMatrix = pPlayer->GetViewMatrix();
    viewMatrix.SetTranslation(Vec3(400,500,9)); // fix point in test map
    m_scopeCamera.SetMatrix(viewMatrix);
    m_scopeCamera.SetFrustum(800,600,fov);
    gEnv->pRenderer->SetRenderTarget(m_scopeRenderTarget);
    gEnv->pRenderer->BeginFrame();
    gEnv->p3DEngine->RenderWorld(gEnv->pRenderer->GetRenderType() | SHDF_ALLOW_WATER, m_scopeCamera, "cam_tryN");
    gEnv->pRenderer->SetRenderTarget(0);
    gEnv->pRenderer->EndFrame();
    gEnv->pRenderer->Draw2dImage(300,300,400,300,m_scopeRenderTarget,1,0,0,1,180,1,1,1,1,1);
and this is my result...
Image


cron