1
$\begingroup$

I've seen similar questions on how to take pictures, but those questions are for the render engine, cycles, and others. I have a set of weapons, and want to take a picture from the side view. When you swap to your weapon, your newly selected weapon will show its picture on the right side of your screen, like other FPS games. In other words, I am looking for a way to take a screenshot in the GE; if you can, then can I also change the resolution? Any help is appreciated, thanks!

$\endgroup$
  • 2
    $\begingroup$ why not prepare them before and just pick the one related to the weapon ? $\endgroup$ – Chebhou Mar 17 '15 at 19:41
  • $\begingroup$ @Chebhou presents a good point. You could "take" the pictures before hand and just display the afterward in the game. $\endgroup$ – Scalia Mar 18 '15 at 22:06
  • $\begingroup$ I'm not saying IN play mode. Just in the ge. $\endgroup$ – blackhole Mar 18 '15 at 23:05
4
$\begingroup$

Pose your weapon according to the view , than run the script to take a picture using openGl render , got o the UV editor and the image will have the name of the active object :

import bpy

# path to the folder
file_path = bpy.data.filepath
file_name = bpy.path.display_name_from_filepath(file_path)
file_ext = '.blend'
file_dir = file_path.replace(file_name+file_ext, '')

mainScreen = bpy.context.screen

#current scene
scene = mainScreen.scene 
#set render settings
scene.render.resolution_x = 128
scene.render.resolution_y = 128
scene.render.resolution_percentage = 100

#render from view (set view_context = False for the camera render)
bpy.ops.render.opengl(view_context = True)

#save and load the render (you can't keep the render result)
img_name = bpy.context.object.name+".png"
bpy.data.images['Render Result'].save_render(file_dir+img_name)
bpy.ops.image.open(filepath = file_dir+img_name)
bpy.data.images[img_name].pack()
  • you can change the render size in the script

For screenshots while playing the BGE has a function for that : bge.render.makeScreenshot(filename) see the DOC

$\endgroup$
  • $\begingroup$ @BlenderDev you can use it even when playing $\endgroup$ – Chebhou Mar 20 '15 at 9:25
  • $\begingroup$ Didn't check it yet, but it looks good. $\endgroup$ – blackhole Mar 21 '15 at 0:50
1
$\begingroup$

bge offers methods to render to texture, in the renderTexture part of bge, that can export a png, or you can snapshot a view of a item on frame 0, the advantage here, is you can load from external blends, and then snap the image, so if you change anything, you just save the external file and the main file updates automagically.

there is also ctrl+print screen to copy a image to paste that is a screenshot.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.