简体   繁体   English

导出Eclipse项目会导致错误的纹理和崩溃,

[英]Exporting Eclipse project causes incorrect texturing and crashes,

This issue is now fixed. 此问题现已修复。 My shader attributes were not bound correctly. 我的着色器属性没有正确绑定。

I have got a game, which when ran from the IDE looks like this: 我有一个游戏,从IDE运行时看起来像这样:

在此输入图像描述

However, when I export it from Eclipse with these settings, 但是,当我使用这些设置从Eclipse导出它时,

在此输入图像描述

The texturing is completely incorrect. 纹理完全不正确。 The textures are still loaded, but they are not wrapping correctly onto the object. 纹理仍然加载,但它们没有正确地包装到对象上。

在此输入图像描述

The code is exactly the same, as I only just exported it, and I am currently running both windows of the game at the same time(One working fine from the IDE, one looking weird from an exported JAR). 代码完全相同,因为我刚刚导出它,而且我目前同时运行游戏的两个窗口(一个在IDE中工作正常,一个从导出的JAR看起来很奇怪)。

I have also copied all the resources from the IDE directory to the folder with the external JAR. 我还将IDE目录中的所有资源复制到具有外部JAR的文件夹中。 IDE directory: IDE目录: 在此输入图像描述

Directory I run the external JAR from: 目录我运行外部JAR: 在此输入图像描述

Also, I know that the textures are actually loading - They are not wrapping correctly. 此外,我知道纹理实际上正在加载 - 它们没有正确包装。 I know this because: 我知道这是因为:

  • If you look at the plane, you can see that it still has elements of the texture - They are just all stretched and messed up. 如果你看飞机,你会发现它仍然有纹理的元素 - 它们只是被拉伸和搞砸了。
  • Same thing with the Skybox. Skybox也是如此。 If you look at that, parts are still there, but again, it's incorrectly wrapped around the OBJ model. 如果你看一下,零件仍然在那里,但同样,它错误地包裹在OBJ模型周围。
  • If I hit the Q key to render the terrain with a DisplayList (Wrapping the terrain texture multiple times), it shows the texture. 如果我点击Q键以使用DisplayList渲染地形(多次包裹地形纹理),它会显示纹理。 Can't get a screenshot of this because I can't hit Q and take a screenshot. 无法获得此截图,因为我无法点击Q并截取屏幕截图。

I have checked inside the JAR file, and the fragment and the vertex shader are still there. 我已经检查了JAR文件,片段和顶点着色器仍在那里。 The correct libraries also appear to be there (Besides, if they weren't, the game would not even start). 正确的库也似乎在那里(此外,如果不是,游戏甚至不会开始)。 在此输入图像描述

Update : As I was restarting the game multiple times to check for more information, I noticed that as soon as the display shows (so I can see the incorrectly-textured terrain and plane), the game freezes about 90% of the time. 更新 :当我多次重新启动游戏以检查更多信息时,我注意到,只要显示屏显示(因此我可以看到纹理不正确的地形和平面),游戏就会冻结大约90%的时间。 No Stacktrace, just a "This window is not responding and windows is closing it". 没有Stacktrace,只是“这个窗口没有响应,窗口正在关闭它”。 The game still works perfectly without crashing when I run it in the IDE. 当我在IDE中运行游戏时,游戏仍能完美运行而不会崩溃。

The server for the game exports and runs perfectly. 游戏服务器导出并运行完美。 Only the client is the issue. 只有客户才是问题。

What about exporting could make the game any different than running it in the IDE, and how can I solve it? 那么导出可以使游戏与在IDE中运行游戏有什么不同,我该如何解决呢?

Update : So here is my texture loading code: 更新 :所以这是我的纹理加载代码:

loader.loadTexture("PlaneTexture", 1);
//loadTexture() method:
public int loadTexture(String fileName, int mipmap) {
    Texture texture = null;
    try {
        try{
        texture = TextureLoader.getTexture("PNG", new FileInputStream("res/" + fileName + ".png")); //TextureLoader is a Slick-Util class.
        }catch (Exception e){
            e.printStackTrace();
        }
        if (texture == null){
            throw new Exception("Null texture!");
        }
        //texture = TextureLoader.getTexture("GIF", new FileInputStream("res/" + fileName + ".png"));
        if (mipmap > -10){
       GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
       GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
       GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, mipmap);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Tried to load texture " + fileName + ".png , didn't work");
        System.exit(1);
        return -1;


    }
    textures.add(texture.getTextureID());
    return texture.getTextureID();
}

I now have the texture ID of the texture. 我现在有纹理的纹理ID。 I then render the object (in this case the plane) like this: 然后我像这样渲染对象(在这种情况下是平面):

Plane you = Main.TerrainDemo.shipsID.get(Main.TerrainDemo.UID);
    Main.TerrainDemo.shader.start();
    TexturedModel texturedModel = TerrainDemo.shipModel; //The plane model
    RawModel model = texturedModel.getRawModel();
    GL30.glBindVertexArray(model.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, TerrainDemo.shipModel.getTexture().getID()); //The ID of the texture.

    glDrawElements(GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);

And, although I don't think they're important, my vertex and fragment shaders: 而且,虽然我不认为它们很重要,但我的顶点和片段着色器:

//Vertex shader
#version 130

in vec3 position;
in vec2 textureCoords;
in vec3 normal;

out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec3 toLightVector;

uniform mat4 transformationMatrix;
uniform vec3 lightPosition;

void main(void){
gl_Position = ftransform();
pass_textureCoords = textureCoords;
surfaceNormal = (transformationMatrix * vec4(normal, 0.0)).xyz;
toLightVector = (vec3(500, 50000, 500)) - (transformationMatrix * vec4(position, 1.0)).xyz;
}

//Fragment shader
#version 130

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector;

out vec4 out_Color;

uniform sampler2D textureSampler;

uniform vec3 lightColour;

void main(void){
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);

float nDot1 = dot(unitNormal, unitLightVector);
float brightness = max(nDot1, 0.2);
brightness = brightness + 0.5;
vec3 diffuse = brightness * vec3(1, 1, 1);

vec4 textureColor = vec4(diffuse, 1.0) * texture(textureSampler, pass_textureCoords);
if(textureColor.a<1){
    discard;
}
out_Color = vec4(textureColor.r, textureColor.g, textureColor.b, 1);

}

Again, I will stress that all of this is working perfectly if the game is running from the IDE. 同样,我将强调,如果游戏是从IDE运行的,那么所有这一切都能正常运行。 It is just if it runs from an external JAR that the issue occurs. 只是从外部JAR运行才会出现问题。

I will be experimenting with different texture loading techniques and methods (eg packing textures into the JAR) and seeing if anything different happens. 我将尝试不同的纹理加载技术和方法(例如将纹理打包到JAR中)并查看是否发生了任何不同的情况。

Yet another update : So, I sent the game to another person (They also use windows 8), and the game worked perfectly! 还有一个更新 :所以,我把游戏发送给另一个人(他们也使用Windows 8),游戏完美无缺! No texturing errors whatsoever! 没有任何纹理错误! So now I'm unsure if the problem is with my PC specifically or something else. 所以现在我不确定问题是我的PC是专门还是别的。

For those who wish to try, you can download the game at http://endcraft.net/PlaneGame and see it yourself (Please read the instructions.txt - Also, you'll need a program to decompress .rar files). 对于那些想要尝试的人,你可以在http://endcraft.net/PlaneGame下载游戏并自己查看(请阅读instructions.txt - 另外,你需要一个解压缩.rar文件的程序)。

I will be getting as many people as I know to give the game a go and see if they have the same issue or if the texturing is correct. 我会得到尽可能多的人来让游戏一试,看看他们是否有相同的问题,或者纹理是否正确。

It is completely baffling me that it works fine when I run it from the IDE, but does not work when I export into an external jar, but does work when I export it into an external jar and send it to someone else! 当我从IDE运行它时,它完全没问题,但是当我导出到外部jar时它不起作用 ,但是当我将它导出到外部jar并将其发送给其他人时它确实有效!

(another) Update : I have sent the game to multiple people, some of them are coming across this crash: (另一个) 更新 :我已经将游戏发送给多个人, 其中一些人遇到了这个崩溃:

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x1cd6b57f, pid=36828,  tid=35556
#
# JRE version: Java(TM) SE Runtime Environment (8.0_31-b13) (build 1.8.0_31-b13)
# Java VM: Java HotSpot(TM) Client VM (25.31-b07 mixed mode windows-x86 )
# Problematic frame:
# C  [atioglxx.dll+0xc0b57f]
#

In the log file, I see this: 在日志文件中,我看到:

Stack: [0x011d0000,0x01220000],  sp=0x0121f1e8,  free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [atioglxx.dll+0xc0b57f]
C  [atioglxx.dll+0xbe8b95]
C  [atioglxx.dll+0x641852]
C  [lwjgl.dll+0x9a28]
j  org.lwjgl.opengl.GL20.glUniformMatrix4(IZLjava/nio/FloatBuffer;)V+33
j  TMLoading.ShaderProgram.loadMatrix(ILorg/lwjgl/util/vector/Matrix4f;)V+23j
TMLoading.StaticShader.loadTransformationMatrix(Lorg/lwjgl/util/vector/Matrix4f;) V+6
j  Joehot200.Plane.render()V+407
j  Joehot200.TerrainDemo.render()V+4045
j  Joehot200.TerrainDemo.enterGameLoop()V+356
j  Joehot200.TerrainDemo.startGame()V+320
j  StartScreenExperiments.Test2.resartTDemo()V+128
j  StartScreenExperiments.Test2.main([Ljava/lang/String;)V+27
v  ~StubRoutines::call_stub
V  [jvm.dll+0x1473e5]

In other words, the entire issue (the texturing and the crashes) are beginning to look a lot like they are related to the shaders (either parsing information to them, or the actual shader code itself). 换句话说,整个问题(纹理和崩溃)开始看起来很像它们与着色器相关(要么向它们解析信息,要么实际着色器代码本身)。

I have also done more testing, and the texturing works fine without shaders using a DisplayList. 我还做了更多的测试,并且纹理工作正常,没有使用DisplayList的着色器。

Here is the code up to the glUniformMatrix() call: 以下是glUniformMatrix()调用的代码:

//Some unnecessary code has been removed. For example, you do not care about what colour I make the plane depending on what team it is on.    

//Plane class. (Referring to a jet plane which is the main object the player controls)
public void render(){
    twodcoords = TextDemo.getScreenCoords(sx, sy + 30, sz);
    glPushAttrib(GL_ENABLE_BIT);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glPushMatrix();
    glTranslatef(sx, sy, sz);
    GL30.glBindVertexArray(Main.TerrainDemo.vaoID);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
        glRotatef(srot, 0f, 1f, 0f);
        glRotatef(pitch, -1f, 0f, 0f);
    Main.TerrainDemo.shader.start();
    glPushMatrix();
    glDisable(GL_LIGHTING);
    TexturedModel texturedModel = TerrainDemo.shipModel;
    RawModel model = texturedModel.getRawModel();
    GL30.glBindVertexArray(model.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, TerrainDemo.shipModel.getTexture().getID());
    org.lwjgl.util.vector.Matrix4f m = Assist.createTransformationMatrix(new Vector3f(sx, sy, sz), new Vector3f(pitch, rot, roll), new Vector3f(5, 5, 5)); //Creates a transformation matrix based on the X, Y, Z, Pitch, yaw, roll, and scale of the plane.
    Main.TerrainDemo.shader.loadTransformationMatrix(m);
    glDrawElements(GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
    GL30.glBindVertexArray(0);
    glPopMatrix();
    glPopAttrib();
}
//StaticShader class. This method literally just passes it to the loadMatrix class.    
public void loadTransformationMatrix(Matrix4f matrix){
    super.loadMatrix(location_transformationMatrix, matrix);
}
//ShaderProgram class.
FloatBuffer buf = BufferUtils.createFloatBuffer(4 * 4);
public void loadMatrix(int location, Matrix4f matrix){
    matrix.store(buf);
    buf.flip();
    GL20.glUniformMatrix4(location, false, buf);
}

Update - So, with one hour left on the Bounty, I thought I'd add a few more details: 更新 - 所以,在Bounty还剩一个小时的时候,我想我会添加一些细节:

  • As I probably said somewhere above, the game works for some when exported, but not for others. 正如我在上面所说的那样,游戏适用于某些导出时,但不适用于其他人。 I've noticed that the game has always worked when ran on java 7, but with me only me and one other tester on java 7, this really isn't conclusive. 我注意到游戏在java 7上运行时总是有效,但是我只有我和java 7上的另一个测试人员,这真的不是决定性的。
  • The texturing renders correctly in a DisplayList. 纹理在DisplayList中正确呈现。 The textures are loading . 纹理正在加载 However, they are not being displayed correctly. 但是,它们没有正确显示
  • Even if you don't know the problem, trying out the game (ignore the start screen, I need to make a new one) and telling me the results, as well as your OS/Java details, etc, would be really appreciated. 即使您不知道问题,尝试游戏(忽略开始屏幕,我需要创建一个新的)并告诉我结果,以及您的操作系统/ Java细节等,将非常感激。
  • Yes, the mipmapping is correct. 是的,mipmapping是正确的。 I know someone in the comments mentioned it possibly wasn't, but I've tried setting it stupidly high and I do indeed get a very blurred texture. 我知道有人在评论中提到它可能不是,但我已经尝试将它设置得愚蠢得高,而且我确实得到了非常模糊的纹理。
  • I've already tried "package libraries into external jar". 我已经尝试过“将库包装到外部jar中”。 I appreciate the time taken for that answer, but I did say in the comments that I've already tried it. 我很欣赏这个答案的时间,但我在评论中说过我已经尝试过了。
  • The issue may be the fragment shader (as someone suggested in the comments), but I am currently unsure how to test it, nor do I understand why it would work inside the IDE but not outside of it. 问题可能是片段着色器(正如评论中建议的那样),但我目前不确定如何测试它,也不理解为什么它在IDE内部工作但不在其中。

I can't test this, so I'm not sure if this will help, but some implementations of OpenGL don't save element buffers in VAOs. 我无法测试这一点,所以我不确定这是否会有所帮助,但OpenGL的某些实现不会在VAO中保存元素缓冲区。 So try binding the element buffer before the call to glDrawElements, eg 因此,在调用glDrawElements之前尝试绑定元素缓冲区,例如

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, someBuffer);
glDrawElements(GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);

If you don't do this, you may be using the last bound buffer for all draw calls. 如果不这样做,您可能正在使用最后一个绑定缓冲区进行所有绘制调用。 Probably not the answer, but it couldn't hurt to test it. 可能不是答案,但测试它不会有害。 I also noticed that you are using an older version of Slick, as you still have the slick-util, which is not part of the latest release, so you could also try updating that. 我还注意到你使用的是Slick的旧版本,因为你仍然有slick-util,它不是最新版本的一部分,所以你也可以尝试更新它。

So try this instead of Extracting the required libraries try Package option instead, Because i personally believe there is an issue while finding those library files or linking some file then simply run the package. 所以试试这个而不是提取所需的库尝试Package选项,因为我个人认为在找到这些库文件或链接某个文件时出现问题,然后只需运行该包。

选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM