Jump to content

Recommended Posts

Posted

Hello, I have a TESR and I'd like to draw a cube (eventual a sphere, thought I'd start easy) at the location of the TE. I have very limited knowledge of opengl and how minecraft handles it through GlStateManager. I know how to do very basic things, but when it comes down to drawing vertices, I am lost. Here is what I have so far, as well as what I think should go where:

            Tessellator tessy = Tessellator.getInstance();
            BufferBuilder buf = tessy.getBuffer();

            GlStateManager.pushMatrix();

            //translate matrix to te pos
            //set color / rot

            //begin drawing
            //set vertices to bufferbuilder

            //draw tessellator

            GlStateManager.popMatrix();

 

Any pointers would be nice.

 

Thanks.  

Posted
6 hours ago, unassigned said:

opengl and how minecraft handles it through GlStateManager.

GlStateManager just manages the various state parameters of opengl like blend, culling, light, etc. The drawing is not done through GlStateManager.

 

To draw vertices you need to understand that a vertex is just a collection of data in a certain arrangement that defines the properties of a point. Several points make a polygon of a kind(a quad for example).

To draw vertices you first need to start drawing using BufferBuilder#begin. The first parameter is the type of polygons you will be drawing. You can get the constants directly from GL11. The second parameter is the format of your vertices - the order in which the data is arranged. You can get the formats from DefaultVertexFormats and their names are pretty descriptive apart from BLOCK(pos vec3, color vec4b, uv vec2, lightmap vec2s) and ITEM(pos vec3, color vec4b, uv vec2, normal vec3).

Then you can start defining your vertices. They must match the format and the amount must match the amount per polygon * number of polygons(note that you can draw multiple polygons in one draw call). To define a vertex use the methods in BufferBuilder. For example, if you want to draw a simple quad it would need 4 vertices and would look like this(example with the POSITION_TEX format)

bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
bb.pos(xs, ys, z).tex(us, vs).endVertex();
bb.pos(xs, ye, z).tex(us, ve).endVertex();
bb.pos(xe, ye, z).tex(ue, ve).endVertex();
bb.pos(xe, ys, z).tex(ue, ve).endVertex();
Tessellator.getInstance().draw();

The order in which you define your vertices also matters, because opengl will not render everything that doesn't match the order to save on rendering time - that's culling(if it is enabled). Minecraft usually defines vertices counter-clockwise but you can change that using GlStateManager. Just don't forget to reset it back after you are done.

Posted (edited)

 

Okay, thanks for this valuable information. I can now properly draw a square, and I assume I must draw six of them to draw a cube? (Implying that there is no other 'shortcut'). If so, I think I have it down, but I'm getting some weird culling issues and I do not know how I would fix. I tried uploading a gif to demonstrate it, but I guess they're not supported, so here are 2 images of this issue:

 

Here is what it should look like:

06202d6662bddb40dadb07394a312b57.png

 

And here is what it looks like from a small distance:

657bcd3f4c64c64e760744a6833a1dbc.png

 

Here is the code I have, I draw each square separately, which creates for some messy code, but I wanted to visualize each squares vertices.

            Tessellator tessy = Tessellator.getInstance();
            BufferBuilder buf = tessy.getBuffer();

            GlStateManager.pushMatrix();
            GlStateManager.disableCull();
            GlStateManager.disableLighting();

            GlStateManager.alphaFunc(GL11.GL_ALWAYS, 0);
            GlStateManager.translate(x+.5f, y+.5f, z+.5f);

            buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);

            //south side [pos z] [parent x]
            buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z+0.5f).endVertex();

            //north side [neg z] [parent x]
            buf.pos(x-0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z-0.5f).endVertex();

            //east side [pos x] [parent z]
            buf.pos(x+0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z+0.5f).endVertex();

            //west side [neg x] [parent z]
            buf.pos(x-0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();

            //top [pos y] [parent x & y]
            buf.pos(x+0.5f, y+0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y+0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y+0.5f, z-0.5f).endVertex();

            //bottom [neg y] [parent x & y]
            buf.pos(x+0.5f, y-0.5f, z-0.5f).endVertex();
            buf.pos(x+0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z+0.5f).endVertex();
            buf.pos(x-0.5f, y-0.5f, z-0.5f).endVertex();

            tessy.draw();

            GlStateManager.enableLighting();
            GlStateManager.enableCull();
            GlStateManager.disableAlpha();
            GlStateManager.popMatrix();

 

Thanks!

 

- edit - I cannot get rid of this video player thing. I guess this happened when I tried to upload the gif.

Edited by unassigned
bug
Posted
2 hours ago, unassigned said:

GlStateManager.translate(x+.5f, y+.5f, z+.5f);

 

2 hours ago, unassigned said:

buf.pos(x-0.5f, y+0.5f, z+0.5f).endVertex();

If you are already translating to x,y,z then there is no need to draw the vertices from x,y,z since they are already at x,y,z.

Posted
16 hours ago, V0idWa1k3r said:

 

If you are already translating to x,y,z then there is no need to draw the vertices from x,y,z since they are already at x,y,z.

Huh, that has fixed it. Why would something like this cause an issue like that? I'd imagine it would just translate it twice.

 

Now, how would I draw a sphere? Would I have to create a high count polygon? Or is there an easier way? As I see no glMode for the bufferbuilder that has anything to do with spherical objects. Also, I have no idea where to even start with drawing vertices for s

Posted

You could generate the sphere's mesh on startup and render it. That would require you to write an algorythm that does that though.

Another option is to create your sphere in any kind of 3d model editor, export it to something that's easy to parse like wavefront, parse it into a collection of vertices and render that.

Posted (edited)
7 hours ago, unassigned said:

Now, how would I draw a sphere? Would I have to create a high count polygon? Or is there an easier way? As I see no glMode for the bufferbuilder that has anything to do with spherical objects. Also, I have no idea where to even start with drawing vertices for s

There’s a tutorial out there somewhere on how to draw a sphere with GLStateManager, however it’s pretty bad for performance as it uses OpenGL instead of the BufferBuilder

 

Heres a link, I’ll try and find the actual tutorial https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/modification-development/2241469-creating-a-sphere

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

  • 1 year later...
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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