jvm-graphics-labs / hello-triangle

Simple sample showing a complete rendering of a triangle, in Java and Kotlin
MIT License
46 stars 14 forks source link

You told me to come here #1

Closed liamt19 closed 8 years ago

liamt19 commented 8 years ago

So, where and how should I input the points and other things?

elect86 commented 8 years ago

Look here vertexData includes positions and texture coordinates, that is where you have to put them

liamt19 commented 8 years ago

I'm just not understanding how to put them in. In your other example there are specific verticies, but in this one I don't see any single variable with data.

elect86 commented 8 years ago

You grab them from the function I gave it you.. :wink: You will end up with rings * sectors vertices in total. Each vertex contains a 3 component position and a 2 component texture coordinate, so 5 floats in total.

Hence:

private void createGeometry(float radius, short rings, short sectors)   {

    float R = 1f / (float)(rings - 1);
    float S = 1f / (float)(sectors - 1);
    short r, s;
    float x, y, z;

    vertexData = new float[rings * sectors * (3 + 2)];

    int t = 0, v = 0, n = 0;
    for(r = 0; r < rings; r++) {
        for(s = 0; s < sectors; s++) {
            x = (float) (Math.cos(2 * Math.PI * s * S) * Math.sin(Math.PI * r * R ));
            y = (float) Math.sin(-Math.PI / 2 + Math.PI * r * R );
            z = (float) (Math.sin(2 * Math.PI * s * S) * Math.sin(Math.PI * r * R ));
            // positions
            indexData[(r * rings + s) * 5 + 0] = x * radius;
            indexData[(r * rings + s) * 5 + 1] = y * radius;
            indexData[(r * rings + s) * 5 + 2] = z * radius;
            // texture coordinates
            indexData[(r * rings + s) * 5 + 3] = s * S;
            indexData[(r * rings + s) * 5 + 4] = r * R;
        }

    }
    int counter = 0;
    indexData = new short[rings * sectors * 6];
    for(r = 0; r < rings - 1; r++){
        for(s = 0; s < sectors - 1; s++) {
            indexData[counter++] = (short) (r * sectors + s);      
            indexData[counter++] = (short) (r * sectors + (s + 1));   
            indexData[counter++] = (short) ((r + 1) * sectors + (s + 1));  
            indexData[counter++] = (short) ((r + 1) * sectors + (s + 1)); 
            indexData[counter++] = (short) (r * sectors + (s + 1));    
            indexData[counter++] = (short) ((r + 1) * sectors + s);    
        }
    }
}
liamt19 commented 8 years ago

Can you just fill in what I would need if I just had 2 sectors 2 rings and 2 radius? I'm very confused. :(

public float[] vertexData = new float[]{

};
public short[] indexData = new short[]{

};
elect86 commented 8 years ago

I will try to write a whole sample for you, which texture were you about to use?

liamt19 commented 8 years ago

Ideally an earth texture. Thank you for all this...

elect86 commented 8 years ago

Gimme one :globe_with_meridians:, I hope I can make it in the weekend

elect86 commented 8 years ago

Here your globe

liamt19 commented 8 years ago

looking sweet dude, no errors except for this one:

init Exception in thread "main-AWTAnimator#00" com.jogamp.opengl.util.AnimatorBase$UncaughtAnimatorException: com.jogamp.opengl.GLException: Caught GLException: Method "glCreateBuffers" not available on thread main-AWTAnimator#00 at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:84) at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:451) at com.jogamp.opengl.util.Animator$MainLoop.run(Animator.java:198) at java.lang.Thread.run(Thread.java:745) Caused by: com.jogamp.opengl.GLException: Caught GLException: Method "glCreateBuffers" not available on thread main-AWTAnimator#00 at com.jogamp.opengl.GLException.newGLException(GLException.java:76) at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1311) at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1131) at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:680) at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:77) ... 3 more Caused by: com.jogamp.opengl.GLException: Method "glCreateBuffers" not available at jogamp.opengl.gl4.GL4bcImpl.glCreateBuffers(GL4bcImpl.java:3912) at HelloTexture.initBuffers(HelloTexture.java:146) at HelloTexture.init(HelloTexture.java:123) at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:641) at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:689) at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:673) at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:442) at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1277) ... 6 more

elect86 commented 8 years ago

Do you have the last jogl?

liamt19 commented 8 years ago

I think so

elect86 commented 8 years ago

gpu and operating system?

liamt19 commented 8 years ago

Windows 7 and nvidia gtx 750 ti

liamt19 commented 8 years ago

Looks like gl4.glCreateBuffers(Buffer.MAX, bufferName); is a opengl 4.5 thing and I only have 4.4 :(

elect86 commented 8 years ago

Have you updated your drivers?

liamt19 commented 8 years ago

I think my gpu can only go up to 4.4

liamt19 commented 8 years ago

if I change it to gl4.glGenBuffers(Buffer.MAX, bufferName) it gives me different error.

elect86 commented 8 years ago

your gpu is totally 4.5 capable..

what error is this last one?

liamt19 commented 8 years ago

The other error doesn't really matter as I'm sure it wouldn't have worked even if it did work. How would I update my drivers though?

elect86 commented 8 years ago

Share it anyway, only the first few lines of the first exception

You can download them from http://www.nvidia.co.uk/Download/index.aspx?lang=en-uk

Select "GeForce" and then "GeForce 700 Series"

liamt19 commented 8 years ago

GlDebugOutput.messageSent(): GLDebugEvent[ id 0x20071 type Warning: generic severity Unknown (0x826b) source GL API msg Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations. when 1456075279444 source 4.4 (Core profile, arb, debug, compat[ES2, ES3, ES31], FBO, hardware) - 4.4.0 NVIDIA 344.60 - hash 0x59b4ea60]

elect86 commented 8 years ago

ah, that's not an error :)

it's just the Debug Output, new debugging feature from GL 4.3, unless severity is high, you don't have to worry, it just says which kind of memory buffer 1 is gonna use

elect86 commented 8 years ago

Anyway, you should definitely update, 361.91 is the current one

liamt19 commented 8 years ago

Alright I will and I will see if it works after

liamt19 commented 8 years ago

source 4.5 (Core profile, arb, debug, compat[ES2, ES3, ES31], FBO, hardware) - 4.5.0 NVIDIA 361.91 - hash 0x59b4ea60] GlDebugOutput.messageSent(): GLDebugEvent[ id 0x502 type Error severity High: dangerous undefined behavior source GL API msg GL_INVALID_OPERATION error generated. object is not successfully linked, or is not a program object. when 1456079431085 source 4.5 (Core profile, arb, debug, compat[ES2, ES3, ES31], FBO, hardware) - 4.5.0 NVIDIA 361.91 - hash 0x59b4ea60]

elect86 commented 8 years ago

Well, now at least you have 4.5 :relieved:

It seems that the program is either not successfully linked or something other is trying to be passed as program to gl4.useProgram()

Try to debug, put a breakpoint at the init() and then go step by step until the exception is throw again. Then tell me which was the last point that fired that

liamt19 commented 8 years ago

Looks like gl4.glBindVertexArray(vertexArrayName.get(0)); gets an error.

elect86 commented 8 years ago

Weird, it has nothing to do with the error... did you revert your modifications?

liamt19 commented 8 years ago

Yes. I just copied the code from your example.

liamt19 commented 8 years ago

Actually, just spotted something else:

Shader status invalid: 0(22) : error C7528: OpenGL reserves names starting with 'gl_' 0(22) : error C7576: OpenGL does not allow output blocks in fragment shaders 0(27) : error C7576: OpenGL does not allow output blocks in fragment shaders

liamt19 commented 8 years ago

That was it, just fixed it. I had to copied the globe.frag -> globe.fp (which it asked me to do) and I must have put in their names wrong.

liamt19 commented 8 years ago

Thank you so much for all this. :)

elect86 commented 8 years ago

You are welcome :+1: