Jump to content

Recommended Posts

Posted (edited)

You would need to create a framebuffer, set it up correctly, bind a render texture to it, bind it as the active framebuffer and pretty much mimic the entire rendering of the game but with the Minecraft.renderViewEntity being the entity of your choice.

Then you would retrieve your texture, bind it and render a quad with it.

This is theoretical, I have never done anything like that and don't even know if this is possible. Look at minecraft's shaders, they might offer an insight at the issue.

Edit: If you simply want to change what the player sees on the screen(read: not add another texture on to of player's view) then you simply need to change Minecraft.renderViewEntity to the entity you wish to view the world from. However this was raised in an another topic and I believe the author of that topic had some frustrum culling issues with this approach.

Edited by V0idWa1k3r
Posted

Yeah, pretty sure you'd have to do everything that the RenderGlobal class does but you'd set the camera and related frustum to be at the other entity position and in the direction it is looking. You could pretty much copy the code but that might not actually be easy because there is probably a lot of private stuff and concurrent modification issues you'd have to work through.

 

I know some people have implemented mirrors that use a similar idea in mods so maybe there is some tutorial or open source code that can give you ideas.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
6 minutes ago, jabelar said:

You could pretty much copy the code but that might not actually be easy because there is probably a lot of private stuff and concurrent modification issues you'd have to work through.

I actually don't think it's too challenging. As long as you change the renderViewEntity you can just do the same the game does when it renders everything. And it doesn't do much - it just calls a couple of public methods here and there.

I also don't think CMEs are going to be a thing. CME happens when a collection is modified while it is iterated. That shouldn't happen when the game simply renders the scene twice.

Posted (edited)

A snippet of what? Setting the renderViewEntity? Creating a framebuffer? Rendering everything all over again?

Setting the renderViewEntity:

Minecraft.getMinecraft().setRenderViewEntity(yourEntity)

Creating a framebuffer(somewhat of a pseudo-code as I don't know if Minecraft allows using framebuffers directly like that(it might bind it's own framebuffer somewhere else) but I think for your purpose something like this should suffice - so don't use this code directly, it is meant to be an example)

int rbo = GL30.glGenRenderbuffers(); // Should be a field
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, rbo);
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH24_STENCIL8, texWidth, texHeight);
int fbo = GL30.glGenFramebuffers(); // Should be a field
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, tex, 0);
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_STENCIL_ATTACHMENT, GL30.GL_DEPTH24_STENCIL8, rbo);

 

But I think the minecraft-way of doing framebuffers is in the net.minecraft.client.shader.Framebuffer class. However I have never used it and as such you need to figure it out yourself but I would imagine it's not too hard. Seems like it largely does the same my example code does but instead uses OpenGlHelper which is the correct way of doing it I suppose since it accounts for extensions.

Rendering everything:

Minecraft mc = Minecraft.getMinecraft();
FMLCommonHandler.instance().onRenderTickStart(mc.getRenderPartialTicks());
mc.entityRenderer.updateCameraAndRender(mc.getRenderPartialTicks(), System.nanoTime());
FMLCommonHandler.instance().onRenderTickEnd(mc.getRenderPartialTicks());

Note that you will have to handle the case of the game being paused and supplying renderPartialTicksPaused from the game's timer to the updateCameraAndRender method and for that you will need refiection.

 

But you still haven't told us whether you even need all this framebuffer stuff. Do you just want to render the game from a different perspective or do you actually want to render a quad on the screen that shows what another entity is seeing?

Edited by V0idWa1k3r
Posted
17 minutes ago, Spaceboy Ross said:

see what the entity sees on the screen.

This statement is ambiguous. Do you mean see as in see through the eyes of the entity(read: see the game from a different perspective) or see as in see a picture of the entity's vision on your HUD? If it's the former then you do not need the framebuffers, you simply need to change the renderViewEntity although I've heard that it is not quite that simple and causes frustrum culling issues.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.