SpiderPig Posted October 31, 2010 Share Posted October 31, 2010 Does any one have code for rendering a second camera to a separate buffer and then to a texture so I can use it on a material for my security camera? I know of the GetBufferColor() function but I'm unsure of the process used to actually get from my second camera to my texture! Can any one help me? Quote Link to comment Share on other sites More sharing options...
macklebee Posted October 31, 2010 Share Posted October 31, 2010 an extreme version that is a fps hog, but still shows the concept... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted October 31, 2010 Author Share Posted October 31, 2010 Thanks for the code, I'll see what I can get out of it Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Having a little problem with getting my texture rendered to my computer screen... I've created an extra world, buffer and camera, and I've made a cube in that world just a little in front of the camera. void SetupComputerBuffer(void) { TWorld current=CurrentWorld(); ComputerWorld=CreateWorld(); TModel cube=CreateCube(); ComputerBuffer=CreateBuffer(64,64,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); ComputerCamera=CreateCamera(); PositionEntity(ComputerCamera,Vec3(0,0,-4)); SetWorld(current); mat1=LoadMaterial("abstract::Tex_ComputerScreen.mat"); };//called once on setup void UpdateComputer(void) { TBuffer currentb=CurrentBuffer(); TWorld currentw=CurrentWorld(); SetBuffer(ComputerBuffer); SetWorld(ComputerWorld); RenderWorld(); ComputerTexture=GetColorBuffer(ComputerBuffer); SetMaterialTexture(mat1,ComputerTexture,0); SetBuffer(currentb); SetWorld(currentw); };//called every loop before the main world and light render Everything draws fine with this code at the end of my main world and light renders; DrawImage(GetBufferColor(ComputerBuffer),0,0,-1,-1); ..and this code; ComputerTexture=GetBufferColor(ComputerBuffer); SetMaterialTexture(mat1,ComputerTexture,0); DrawImage(GetMaterialTexture(mat1,0),0,0,-1,-1); but with this code; ComputerTexture=GetBufferColor(ComputerBuffer); SetMaterialTexture(mat1,ComputerTexture,0); ..my screen dosn't have the texture, but clearly it is being asigned to the material, it's just not showing. I loaded a seperate texture and asigned it to the material and the screen showed that, so my models fine. Any sugestions? Quote Link to comment Share on other sites More sharing options...
ZioRed Posted November 5, 2010 Share Posted November 5, 2010 I'm a little confused, you wrote: Everything draws fine with this code ... ..and this code; ComputerTexture=GetBufferColor(ComputerBuffer); SetMaterialTexture(mat1,ComputerTexture,0); DrawImage(GetMaterialTexture(mat1,0),0,0,-1,-1); but then you say: but with this code; ComputerTexture=GetBufferColor(ComputerBuffer); SetMaterialTexture(mat1,ComputerTexture,0); ..my screen dosn't have the texture So... that works or not? The only difference is the calling to DrawImage. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Sorry. Neither code puts the texture onto the model. I just wrote it like that to show that the texture is being assigned to the material because I'm able to recall and draw it to the screen. Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 Do you have the cube face as a separate texture from the rest of the cube? What do you have for a material file? without rendering the buffer to the material, does the cube show its original texture fine? Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 The cube itself has no texture, it's just so I can see if its actually rendering somthing. (see attachment) screen.bmp The material file for the screen is as below; texture0="abstract::Tex_ComputerScreen.dds" clamp0=0,0,0 blend=0 depthmask=1 depthtest=1 overlay=0 zsort=0 cullface=1 castshadows=1 specular=1.00000000 bumpscale=1.00000000 gloss=0.500000000 shader="abstract::mesh_diffuse.vert","abstract::mesh_diffuse.frag" shadowshader="","" "abstract::Tex_ComputerScreen.dds" is just a 64x64 black image. I painted the cube with a material and it rendered fine without rendering the buffer to the material. Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 when are you painting the cube with the mat1 material? I have taken the code and put it into a lua example and it works like expected... but the cube is black... which is because there's nothing in that world... is this what you are seeing? Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Just to be sure: the cube is just a reference object so I'm able to see if the buffer has been asigned to the computers screen. Here is where I render and update my computer stuff; #include "engine.h" TWorld ComputerWorld; TBuffer ComputerBuffer; TCamera ComputerCamera; TTexture ComputerTexture; TMaterial mat1; void ComputerSetup(void); void SetupComputerBuffer(void); void UpdateComputer(void); int main(int argc,char** argv) { Initialize() ; RegisterAbstractPath("C:/Leadwerks Engine SDK"); SetAppTitle( "Game." ) ; Graphics( 1024, 600 ) ; TWorld world; TBuffer gbuffer; TCamera camera; world = CreateWorld() ; if(!world) { MessageBoxA(0,"Error","Failed To Create World.",0); return Terminate(); }; gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); camera=CreateCamera(); TLight light = CreateDirectionalLight(); ComputerSetup(void); //loop while( !KeyHit() && !AppTerminate() ) { // Update timing and world UpdateAppTime(); UpdateWorld(AppSpeed()) ; UpdateComputer(); // Render SetBuffer(gbuffer); RenderWorld(); SetBuffer(BackBuffer()); RenderLights(gbuffer);//ComputerTexture=GetColorBuffer(BackBuffer(),1); DrawImage(ComputerTexture,0,0,-1,-1); Flip(1) ; } return Terminate() ; } void ComputerSetup(void) { ComputerScreen=LoadModel("abstract::ComputerScreen.gmf"); SetupComputerBuffer(); }; void SetupComputerBuffer(void) { TWorld current=CurrentWorld(); ComputerWorld=CreateWorld(); TModel cube=CreateCube(); //I tested a material on the cube here, which was a diffuse shader with a red.dds texture. Only the basic and it worked fine. ComputerBuffer=CreateBuffer(64,64,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); ComputerCamera=CreateCamera(); PositionEntity(ComputerCamera,Vec3(0,0,-4)); SetWorld(current); mat1=LoadMaterial("abstract::Tex_ComputerScreen.mat"); }; void UpdateComputer(void) { TBuffer currentb=CurrentBuffer(); TWorld currentw=CurrentWorld(); SetBuffer(ComputerBuffer); SetWorld(ComputerWorld); RenderWorld(); ComputerTexture=GetColorBuffer(ComputerBuffer); SetMaterialTexture(mat1,ComputerTexture,0); SetBuffer(currentb); SetWorld(currentw); }; I've chopped out the insignificant bits so that's all the code relivant to textureing the computer screen. I had to move the camera back a bit in order to see the cube. Otherwise it is black. Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 and what do you get from this code? What I am seeing is there is no place in your code where the cube is being painted the mat1 material... and even if you did, then it would just show as black because you have nothing in the computer world to render anyways... get rid of the separate world or actually create something in the computer world to render... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 (edited) From this code my computer screen is loaded with the material "Tex_ComputerScreen" already asigned to its screen. I load that same material and change the texture0 channel to the texture I get from "GetColorBuffer(ComputerBuffer)" every frame after my ComputerBuffer has been updated. The ComputerBuffer rendering process works perfectly. I never intented to texture the cube, only the computer screen with the new texture. I rendered the cube into the ComputerWorld so instead of seeing black on my computer screen, I had a white square in the centre so I could tell if it was working properly. (See the previous attachment) It didn't work so I drew the texture on screen, which said it was working, but clearly on my computer screen it wasn't. Other textures have worked by loading them indapendantly. It's just the texture from "GetColorBuffer(ComputerBuffer)" isn't showing on the computers screen (via the texture0 channel). Hope this makes sense, Thanks for the code, will have closer look in the morning Edited November 5, 2010 by SpiderPig Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 without testing it on the model itself i cannot say... but i would guess the problem is with the model... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 try removing this line from the material file... in lua it causes the shader to fail... shadowshader="","" i had removed that and was able to get the lua example working just fine, but at the time i thought maybe it was just because i was using lua... lua has issues when loading shaders sometimes... but maybe its also crashing in c++... but after removing that i was able to show that buffer rendering on any object that had the appropriate material... so if its not the material file, then its the model... assuming all things are equal between bmax, lua, and c++ Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Getting rid of the line; shadowshader="","" didn't do anything. Heres the model and materials if you'd like to test them yourself. Computer.zip Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 ok will take a look at it... in the meantime take a look at this script... it works, so it points to your model... don't forget to remove the shadowshader line from the mat file RegisterAbstractPath("") Graphics(800,600) world=CreateWorld() gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),1+2+4+8) camera=CreateCamera() camera:SetPosition(Vec3(0,1,-3)) CameraClearColor(camera, Vec4(0,.5,1,1)) light=CreateDirectionalLight() light:SetRotationf(45,45,45) mat1=LoadMaterial("abstract::Tex_ComputerScreen.mat") box=CreateCube() box:SetPosition(Vec3(2,0,0),1) sphere=CreateSphere(16) sphere:SetPosition(Vec3(-2,0,0),1) drum=LoadMesh("abstract::oildrum.gmf") drum:SetPosition(Vec3(0,-.5,0),1) drum:SetRotation(Vec3(0,180,0),1) ground=CreateCube() ground:SetScalef(10.0,1.0,10.0) ground:SetPositionf(0.0,-1.0,0.0) box:Paint(mat1) sphere:Paint(mat1) drum:Paint(mat1) ground:Paint(LoadMaterial("abstract::cobblestones.mat")) camera:Point(drum,3,1,0) function SetupComputerBuffer() current=CurrentWorld() ComputerWorld=CreateWorld() cube = CreateCube() cube:SetColor(Vec4(1,.25,0,1)) ComputerBuffer=CreateBuffer(512,512,1+2+4+8) ComputerCamera=CreateCamera() PositionEntity(ComputerCamera,Vec3(0,0,-4)) SetWorld(current) end SetupComputerBuffer() function UpdateComputer() currentb=CurrentBuffer() currentw=CurrentWorld() SetBuffer(ComputerBuffer) SetWorld(ComputerWorld) RenderWorld() ComputerTexture=GetColorBuffer(ComputerBuffer) SetMaterialTexture(mat1,ComputerTexture,0) SetBuffer(currentb) SetWorld(currentw) end while AppTerminate()==0 do cube:Turn(Vec3(.1,.1,0)) UpdateComputer() SetBuffer(gbuffer) world:Render() SetBuffer(BackBuffer()) world:RenderLights(gbuffer) Flip() collectgarbage(collect) end collectgarbage(collect) Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Thanks, I just tested the buffer on an extra cube made in the main world and it worked perfectly. It's the model then, but I'm not sure what. The UV coordinates are fine and other textures I loaded and applied to the texture0 channel worked....Is there somthing special that needs to be done to a model for this to work? Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 yeah its definitely appears to be the model... do you have a copy of it in OBJ or X format? also just a side note: clamp values in mat file should be two integers not three... also im sure you know, but the computer scale is huge and the origin is about 8 meters from model itself... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Here it is in .obj; I model it in blender and export it to .3ds then open it in UU3D pro and asign it textures then export it to .obj and convert it to .gmf. Blenders .obj exporter dosn't work great for me so this is the only way I can get stuff to work. EDIT: Yeah I havn't rescaled my models yet. Would this effect anything? Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 if you have uu3d, then Select All, then click 3D Tools>Modifiers>Scene>Scale to scale it appropriately and the click 3D Tools>Modifiers>Scene>Move and click Center then Above Y Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 i scaled it appropriately and set the origin below the model. also changed the name of the material listed in uu3d to reflect the material filenames... and it works for me... ComputerScreen_fixed.zip Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 I scaled it to .08 times and the material still didn't work. I just tried setting the buffer to the material of another model I exported from blender, and this model tiles it's texture about 100 times so if it was going to work, I'd see it. Instead it showed only one rendered cube smack bang in the centre of the entire model. Maybe the UV coordinates arnt being read correctly? Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Now works for me with that fixed model! So you scaled to .08 and how did you change the material names? Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 5, 2010 Share Posted November 5, 2010 i dont know what scale i ended up with... just played around until it look right to me... as far the material names shown on the right treelist of uu3d... i right clicked the material name and renamed it to Tex_ computer and the second one to Tex_computerscreen... also double-clicked both to open their properties dialog and clicked on the Maps tab and set the Diffuse to Bitmap and then selected the appropriate texture for it... if you open the OBJ in uu3d you will see what i changed... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SpiderPig Posted November 5, 2010 Author Share Posted November 5, 2010 Tried it and nothing.... No idea whats happeing with it. I changed the names and diffuse textures. The model loads and displays the materials fine, it's just when I set the buffer to the texture and change it to the texture0 channel. I'll just have to try a new model or something, see if that works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.