Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3
  ignore  |  Print  
  Problem displaying a triangle array/mesh  (Read 12353 times)
0 Members and 1 Guest are viewing this topic.
Offline gouessej
« Reply #30 - Posted 2011-12-16 21:24:59 »

Like? More than 64MB you mean? Have you used the -XX:MaxDirectMemorySize=256m option?
I succeeded in creating a VBO measuring about 200 MB on a 64-bits machine under Cent OS Linux 5.3. I used this option but with a greater value of course.

Ok, im going to install the 6.30, it should be the last one, right?... or do you suggest me to try the 7 or a beta?

@gouessej, what java you have?
I often use both Java 1.6 update 26, Java 1.6 update 30 and OpenJDK 1.6. I have not yet tested Java 1.7.

Offline elect

Junior Member





« Reply #31 - Posted 2011-12-19 07:50:02 »

I succeeded in creating a VBO measuring about 200 MB on a 64-bits machine under Cent OS Linux 5.3. I used this option but with a greater value of course.

Nice, I will try the same, that is VBOs.

However just a question about the displaying the image over the screen.

I am testing now how a 3d view of my model looks like. I applied a mouse listener and I can rotate and zoom, but I would like that it could rotate only around the X and Y axes. The problem arises when I rotate it first over Y axes, lets say, for 90° in left or right direction and then I try the rotation over X, but in this case the rotation is over Z for me.

I guess when I rotate over Y for 90°, also the model coordinating system rotate with it, and that is why its X axes corresponds to the Z axes in my coordinating system (the viewer).
Offline gouessej
« Reply #32 - Posted 2011-12-19 10:24:46 »

Are you trying to implement a virtual trackball? There is an exemple of implementation using it in MSG (minimal scenegraph) and another one in Ardor3D, look at OrbitCamExample. I already implement it at work, do you use Euler angles?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elect

Junior Member





« Reply #33 - Posted 2011-12-20 08:09:52 »

Are you trying to implement a virtual trackball? There is an exemple of implementation using it in MSG (minimal scenegraph) and another one in Ardor3D, look at OrbitCamExample. I already implement it at work, do you use Euler angles?

No no Cheesy

I am just trying to get a custom 3d view of a model, like this



However, I found a solution, but this implies that I do set the modelview matrix by myself

But how do I set modelview matrix in JOGL2? :/
Offline elect

Junior Member





« Reply #34 - Posted 2011-12-20 15:10:51 »

Let us suppose that I have this 3d model



i perform a

gl.glRotatef(90, 0, 1, 0);



But if I do

gl.glRotatef(90, 0, 1, 0);
gl.glRotatef(90, 1, 0, 0);




But I would like to get this one




The second rotation must somehow connected to the first one
Offline sproingie

JGO Kernel


Medals: 202



« Reply #35 - Posted 2011-12-20 15:33:30 »

When you rotate an object, you're also rotating its axes so that further rotations are along those axes.  So in order to get the picture on the bottom, you rotate on the X axis, then on the Y axis, which has now been rotated to be where your Z axis used to be.

It helps to visualize this for real: head over to an arts and crafts store, and get three colored pencils: one each of red, blue, and green, and a styrofoam ball.  Poke the pencils into the ball so that the red pencil points right (X axis), the green one points up (Y axis), and the blue one points toward you (Z axis).  When you want to visualize a rotation along an axis, loosely grab with your right hand the axis you want to rotate, pointing your thumb away from the ball.  The direction your fingers curl is the positive direction of rotation.

Stick the rig on a spike like one from an office supply store and you can keep it in place while you visualize rotations.

Of course you can just fire up blender and do the same thing, but it's not nearly as fun. Smiley
Offline elect

Junior Member





« Reply #36 - Posted 2011-12-20 16:21:24 »

When you rotate an object, you're also rotating its axes so that further rotations are along those axes.  So in order to get the picture on the bottom, you rotate on the X axis, then on the Y axis, which has now been rotated to be where your Z axis used to be.

It helps to visualize this for real: head over to an arts and crafts store, and get three colored pencils: one each of red, blue, and green, and a styrofoam ball.  Poke the pencils into the ball so that the red pencil points right (X axis), the green one points up (Y axis), and the blue one points toward you (Z axis).  When you want to visualize a rotation along an axis, loosely grab with your right hand the axis you want to rotate, pointing your thumb away from the ball.  The direction your fingers curl is the positive direction of rotation.

Stick the rig on a spike like one from an office supply store and you can keep it in place while you visualize rotations.

Of course you can just fire up blender and do the same thing, but it's not nearly as fun. Smiley


So you are telling me that there is no solution? Sad

I guess the problem is just to connect somehow the second rotation to the first one with some geometric formulas
Offline sproingie

JGO Kernel


Medals: 202



« Reply #37 - Posted 2011-12-20 16:34:47 »

I just gave you the solution in the first paragraph:  Rotate on the X axis, then on Y. 

Offline elect

Junior Member





« Reply #38 - Posted 2011-12-21 09:20:49 »

I just gave you the solution in the first paragraph:  Rotate on the X axis, then on Y. 



That was just an example to show my problem, I needed to do solve this for every rotation that one could make

However I found a solution thank to another guy with:

1  
2  
 float newRotation[] = multiply(rotationX(-dy), rotationY(-dx));
            currentRotation = multiply(currentRotation, newRotation);


At every new rotation (within mouseDragged) I call this piece of code, where rotationX(a) returns the rotation matrix for a rotation over X, rotationY does the same over Y

Then I obtain a new rotation matrix that in turn I multiply on right side for the current (or the old, as you prefer) rotation matrix..

In this way I obtain rotation only over x and y axes referred to the coordinating system of the viewer, no matter which rotation you are performing!  Grin


However next part is normal vectors, and I am experiencing crashed (or better again memory access violation)

what I do is simply

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
 // in init
// Create the the vertex data
           gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);

            initVertexArray(gl);
            initNormalArray(gl);
           
            //  specify buffer that hold vertex/normal
           gl.glVertexPointer(3, GL2.GL_FLOAT, 0, vertexData);
            gl.glNormalPointer(GL2.GL_FLOAT, 0, normalData);
           
            //  draw
           gl.glDrawArrays(GL.GL_TRIANGLES, 0, triangleNumber*3);




private void initNormalArray(GL2 gl)    {
        normalData = GLBuffers.newDirectFloatBuffer(triangleNumber*3);
     
        for(int i=0; i<triangleNumber; i++) {
            Triangle tmp = triangleArray.get(i);
            normalData.put(new float[]{tmp.nx, tmp.ny, tmp.nz});
            //System.out.println("nx: "+tmp.nx+" ny: "+tmp.ny+" nz: "+tmp.nz);
       }
        System.out.println("normalData: "+normalData.toString());
        normalData.flip();
        System.out.println("normalData: "+normalData.toString());
    }



#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6b2efd91, pid=8044, tid=7040
#
# JRE version: 6.0_18-b07
# Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode windows-x86 )
# Problematic frame:
# C  0x6b2efd91
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x6898f000):  JavaThread "AWT-EventQueue-0" [_thread_in_native, id=7040, stack(0x6b750000,0x6b7a0000)]

siginfo: ExceptionCode=0xc0000005, reading address 0x689ce000

Registers:
EAX=0x6aff1ce0, EBX=0x6b810000, ECX=0x00001400, EDX=0x00000041
ESP=0x6b79f5b4, EBP=0x3cb8df9e, ESI=0x689ce000, EDI=0x00003c00
EIP=0x6b2efd91, EFLAGS=0x00010206

Top of Stack: (sp=0x6b79f5b4)
0x6b79f5b4:   00000055 6b810000 000013ec 6b3d3e80
0x6b79f5c4:   69c9f47d 6b810000 6aff1afc 000013ec
0x6b79f5d4:   00000055 6b3d3e80 00000000 00000004
0x6b79f5e4:   00000006 00000000 00000055 6b2efd40
0x6b79f5f4:   69c9f5b9 00000004 00001ed7 00003318
0x6b79f604:   6b810000 69631ed1 6b810000 00000004
0x6b79f614:   00000000 00003318 6898f000 60c6a328
0x6b79f624:   60c6a328 6b79f648 693e8c81 00000004

Instructions: (pc=0x6b2efd91)
0x6b2efd81:   08 8b 35 28 5c 83 6b 8b 76 30 8d 3c 49 8d 34 be
0x6b2efd91:   8b 3e 8b 6e 04 89 78 0c 89 68 10 8b 7e 08 89 78


Stack: [0x6b750000,0x6b7a0000],  sp=0x6b79f5b4,  free space=13d6b79f0e8k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  0x6b2efd91

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  jogamp.opengl.gl4.GL4bcImpl.dispatch_glDrawArrays1(IIIJ)V+0
j  jogamp.opengl.gl4.GL4bcImpl.glDrawArrays(III)V+39
j  Viewer.init(Ljavax/media/opengl/GLAutoDrawable;)V+170
j  jogamp.opengl.GLDrawableHelper.init(Ljavax/media/opengl/GLEventListener;Ljavax/media/opengl/GLAutoDrawable;Z)Z+13
j  jogamp.opengl.GLDrawableHelper.init(Ljavax/media/opengl/GLAutoDrawable;)V+48
j  javax.media.opengl.awt.GLCanvas$InitAction.run()V+11
j  jogamp.opengl.GLDrawableHelper.invokeGL(Ljavax/media/opengl/GLDrawable;Ljavax/media/opengl/GLContext;Ljava/lang/Runnable;Ljava/lang/Runnable;)V+238
j  javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(Ljava/lang/Runnable;Ljava/lang/Runnable;)V+36
j  javax.media.opengl.awt.GLCanvas.display()V+31
j  javax.media.opengl.awt.GLCanvas.paint(Ljava/awt/Graphics;)V+135
j  sun.awt.RepaintArea.paintComponent(Ljava/awt/Component;Ljava/awt/Graphics;)V+6
j  sun.awt.RepaintArea.paint(Ljava/lang/Object;Z)V+326
j  sun.awt.windows.WComponentPeer.handleEvent(Ljava/awt/AWTEvent;)V+107
j  java.awt.Component.dispatchEventImpl(Ljava/awt/AWTEvent;)V+853
j  java.awt.Component.dispatchEvent(Ljava/awt/AWTEvent;)V+2
j  java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+46
j  java.awt.EventDispatchThread.pumpOneEventForFilters(I)Z+204
j  java.awt.EventDispatchThread.pumpEventsForFilter(ILjava/awt/Conditional;Ljava/awt/EventFilter;)V+30
j  java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+11
j  java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j  java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j  java.awt.EventDispatchThread.run()V+9
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x689bc400 JavaThread "Timer-0" [_thread_blocked, id=6892, stack(0x6bd60000,0x6bdb0000)]
  0x002b8400 JavaThread "DestroyJavaVM" [_thread_blocked, id=7416, stack(0x008c0000,0x00910000)]
  0x68981c00 JavaThread "D3D Screen Updater" daemon [_thread_blocked, id=4776, stack(0x6b7a0000,0x6b7f0000)]
=>0x6898f000 JavaThread "AWT-EventQueue-0" [_thread_in_native, id=7040, stack(0x6b750000,0x6b7a0000)]
  0x68972400 JavaThread "AWT-Shutdown" [_thread_blocked, id=5124, stack(0x6a950000,0x6a9a0000)]
  0x68983800 JavaThread "main-SharedResourceRunner" daemon [_thread_blocked, id=8024, stack(0x69460000,0x694b0000)]
  0x6698f400 JavaThread "AWT-Windows" daemon [_thread_in_native, id=7808, stack(0x68e50000,0x68ea0000)]
  0x66e10800 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=4116, stack(0x68db0000,0x68e00000)]
  0x66973400 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=4944, stack(0x66bc0000,0x66c10000)]
  0x6696d400 JavaThread "CompilerThread0" daemon [_thread_blocked, id=6876, stack(0x66b70000,0x66bc0000)]
  0x6696bc00 JavaThread "Attach Listener" daemon [_thread_blocked, id=5056, stack(0x66b20000,0x66b70000)]
  0x6696a800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3220, stack(0x66ad0000,0x66b20000)]
  0x66959400 JavaThread "Finalizer" daemon [_thread_blocked, id=5640, stack(0x66a80000,0x66ad0000)]
  0x66954800 JavaThread "Reference Handler" daemon [_thread_blocked, id=5892, stack(0x66a30000,0x66a80000)]

Other Threads:
  0x66951c00 VMThread [stack: 0x669e0000,0x66a30000] [id=8088]
  0x6697e000 WatcherThread [stack: 0x66c10000,0x66c60000] [id=1320]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 4928K, used 3332K [0x02990000, 0x02ee0000, 0x21d90000)
  eden space 4416K,  72% used [0x02990000, 0x02cab1c0, 0x02de0000)
  from space 512K,  29% used [0x02e60000, 0x02e85f70, 0x02ee0000)
  to   space 512K,   0% used [0x02de0000, 0x02de0000, 0x02e60000)
 tenured generation   total 10944K, used 2894K [0x21d90000, 0x22840000, 0x60590000)
   the space 10944K,  26% used [0x21d90000, 0x22063b48, 0x22063c00, 0x22840000)
 compacting perm gen  total 12288K, used 11034K [0x60590000, 0x61190000, 0x64590000)
   the space 12288K,  89% used [0x60590000, 0x610569d0, 0x61056a00, 0x61190000)
No shared spaces configured.

Dynamic libraries:
0x00400000 - 0x00424000    H:\Programme\Java\jdk1.6.0_18\bin\java.exe
0x7c910000 - 0x7c9c9000    H:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c908000    H:\WINDOWS\system32\kernel32.dll
0x77da0000 - 0x77e4a000    H:\WINDOWS\system32\ADVAPI32.dll
0x77e50000 - 0x77ee3000    H:\WINDOWS\system32\RPCRT4.dll
0x77fc0000 - 0x77fd1000    H:\WINDOWS\system32\Secur32.dll
0x7c340000 - 0x7c396000    H:\Programme\Java\jdk1.6.0_18\jre\bin\msvcr71.dll
0x6d8b0000 - 0x6db47000    H:\Programme\Java\jdk1.6.0_18\jre\bin\client\jvm.dll
0x7e360000 - 0x7e3f1000    H:\WINDOWS\system32\USER32.dll
0x77ef0000 - 0x77f39000    H:\WINDOWS\system32\GDI32.dll
0x76af0000 - 0x76b1e000    H:\WINDOWS\system32\WINMM.dll
0x76330000 - 0x7634d000    H:\WINDOWS\system32\IMM32.DLL
0x6d860000 - 0x6d86c000    H:\Programme\Java\jdk1.6.0_18\jre\bin\verify.dll
0x6d3e0000 - 0x6d3ff000    H:\Programme\Java\jdk1.6.0_18\jre\bin\java.dll
0x6d340000 - 0x6d348000    H:\Programme\Java\jdk1.6.0_18\jre\bin\hpi.dll
0x76bb0000 - 0x76bbb000    H:\WINDOWS\system32\PSAPI.DLL
0x6d8a0000 - 0x6d8af000    H:\Programme\Java\jdk1.6.0_18\jre\bin\zip.dll
0x68000000 - 0x68036000    H:\WINDOWS\system32\rsaenh.dll
0x77be0000 - 0x77c38000    H:\WINDOWS\system32\msvcrt.dll
0x76620000 - 0x766d6000    H:\WINDOWS\system32\USERENV.dll
0x66e80000 - 0x66ed5000    H:\WINDOWS\system32\netapi32.dll
0x6d6c0000 - 0x6d6d3000    H:\Programme\Java\jdk1.6.0_18\jre\bin\net.dll
0x71a10000 - 0x71a27000    H:\WINDOWS\system32\WS2_32.dll
0x71a00000 - 0x71a08000    H:\WINDOWS\system32\WS2HELP.dll
0x719b0000 - 0x719f0000    H:\WINDOWS\System32\mswsock.dll
0x76ee0000 - 0x76f07000    H:\WINDOWS\system32\DNSAPI.dll
0x76d20000 - 0x76d39000    H:\WINDOWS\system32\iphlpapi.dll
0x76f70000 - 0x76f78000    H:\WINDOWS\System32\winrnr.dll
0x76f20000 - 0x76f4d000    H:\WINDOWS\system32\WLDAP32.dll
0x76f80000 - 0x76f86000    H:\WINDOWS\system32\rasadhlp.dll
0x66f70000 - 0x66f9b000    H:\Dokumente und Einstellungen\gbarbieri\Lokale Einstellungen\Temp\JCudaDriver-windows-x865311847391007711519.dll
0x66fb0000 - 0x674ef000    H:\WINDOWS\system32\nvcuda.dll
0x67520000 - 0x67733000    H:\WINDOWS\system32\nvapi.dll
0x774b0000 - 0x775ee000    H:\WINDOWS\system32\ole32.dll
0x770f0000 - 0x7717b000    H:\WINDOWS\system32\OLEAUT32.dll
0x77f40000 - 0x77fb6000    H:\WINDOWS\system32\SHLWAPI.dll
0x7e670000 - 0x7ee91000    H:\WINDOWS\system32\SHELL32.dll
0x778f0000 - 0x779e4000    H:\WINDOWS\system32\SETUPAPI.dll
0x77bd0000 - 0x77bd8000    H:\WINDOWS\system32\VERSION.dll
0x773a0000 - 0x774a3000    H:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll
0x6d6e0000 - 0x6d6e9000    H:\Programme\Java\jdk1.6.0_18\jre\bin\nio.dll
0x67f50000 - 0x67f5a000    H:\Dokumente und Einstellungen\gbarbieri\Lokale Einstellungen\Temp\jogamp.tmp.cache_000000\jln335667427994843198\jln4822347258357380250\gluegen-rt.dll
0x6d0b0000 - 0x6d1fa000    H:\Programme\Java\jdk1.6.0_18\jre\bin\awt.dll
0x72f70000 - 0x72f96000    H:\WINDOWS\system32\WINSPOOL.DRV
0x67f80000 - 0x67fb8000    H:\WINDOWS\system32\uxtheme.dll
0x746a0000 - 0x746ec000    H:\WINDOWS\system32\MSCTF.dll
0x75250000 - 0x7527e000    H:\WINDOWS\system32\msctfime.ime
0x6d410000 - 0x6d416000    H:\Programme\Java\jdk1.6.0_18\jre\bin\jawt.dll
0x6a440000 - 0x6a44a000    H:\Dokumente und Einstellungen\gbarbieri\Lokale Einstellungen\Temp\jogamp.tmp.cache_000000\jln335667427994843198\jln4822347258357380250\nativewindow_awt.dll
0x6d2e0000 - 0x6d334000    H:\Programme\Java\jdk1.6.0_18\jre\bin\fontmanager.dll
0x68ee0000 - 0x69086000    H:\WINDOWS\system32\d3d9.dll
0x6de80000 - 0x6de86000    H:\WINDOWS\system32\d3d8thk.dll
0x6c100000 - 0x6c110000    H:\Dokumente und Einstellungen\gbarbieri\Lokale Einstellungen\Temp\jogamp.tmp.cache_000000\jln335667427994843198\jln4822347258357380250\nativewindow_win32.dll
0x692f0000 - 0x693bc000    H:\WINDOWS\system32\OpenGL32.dll
0x693c0000 - 0x693e0000    H:\WINDOWS\system32\GLU32.dll
0x736d0000 - 0x7371b000    H:\WINDOWS\system32\DDRAW.dll
0x73b30000 - 0x73b36000    H:\WINDOWS\system32\DCIMAN32.dll
0x693e0000 - 0x69453000    H:\Dokumente und Einstellungen\gbarbieri\Lokale Einstellungen\Temp\jogamp.tmp.cache_000000\jln335667427994843198\jln4822347258357380250\jogl_desktop.dll
0x69500000 - 0x6a34a000    H:\WINDOWS\system32\nvoglnt.dll

VM Arguments:
jvm_args: -Dfile.encoding=UTF-8 -Xmx1500m -XX:MaxDirectMemorySize=256m
java_command: CudaImplementation
Launcher Type: SUN_STANDARD

Environment Variables:
PATH=H:\Programme\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\;H:\WINDOWS\system32;H:\WINDOWS;H:\WINDOWS\System32\Wbem;h:\Programme\Microsoft SQL Server\90\Tools\binn\;H:\IFOR\WIN\BIN;H:\IFOR\WIN\BIN\EN_US;H:\Programme\Microsoft Visual Studio 10.0\VC\bin;H:\Programme\Microsoft Visual Studio 10.0\VC\bin\
USERNAME=gbarbieri
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 10, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows XP Build 2600 Service Pack 3

CPU:total 4 (4 cores per cpu, 1 threads per core) family 6 model 23 stepping 10, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1

Memory: 4k page, physical 3144748k(831488k free), swap 5070780k(2614724k free)

vm_info: Java HotSpot(TM) Client VM (16.0-b13) for windows-x86 JRE (1.6.0_18-b07), built on Dec 17 2009 13:35:55 by "java_re" with MS VC++ 7.1 (VS2003)

time: Wed Dec 21 10:55:20 2011
elapsed time: 13 seconds





Where am I wrong?
Offline elect

Junior Member





« Reply #39 - Posted 2011-12-21 11:40:14 »

Ok, i am trying to switch to VBOs and keeping it as simple as possible (1 triangle)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
...init...

            // Create the the vertex data
           initVertexArray(gl);

            // generate buffer
           int[] bufferID = new int[1];
            gl.glGenBuffers(1, bufferID, 0);
           
            gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
           
            //  select buffer
           gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, bufferID[0]);
            triangleNumber=1;
           
            //  copy data
           gl.glBufferData(GL2.GL_ARRAY_BUFFER, triangleNumber*3*3*4,
                                                vertexData, GL2.GL_STATIC_DRAW);
           
            //  draw
           gl.glDrawArrays(GL.GL_TRIANGLES, 0, triangleNumber*3);

    private void initVertexArray(GL2 gl)    {
        triangleNumber = 1;
        vertexData = GLBuffers.newDirectFloatBuffer(triangleNumber*3*3);
        vertexData.put(new float[]{0,0,0,1,0,0,0,1,0});
        vertexData.flip();
    }


But it still crashes at the glDrawArrays in the init... why?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elect

Junior Member





« Reply #40 - Posted 2011-12-21 16:54:16 »

Solved, I copy here for other ppl, it was hard to find a simple example (just one array, no interleaved) that show the basics

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
//init 

...
            initVertexArray(gl);
            int[] bufferID = new int[1];
            gl.glGenBuffers(1, bufferID, 0);
           
            vertexPointBufferID = bufferID[0];
           
            gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexPointBufferID);
            gl.glBufferData(GL2.GL_ARRAY_BUFFER, triangleNumber*3*3*4, vertexData, L2.GL_STATIC_DRAW);
           
            gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
...


// display
...
        gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexPointBufferID);
        gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
       
        gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
        gl.glDrawArrays(GL2.GL_TRIANGLES, 0, triangleNumber*3);
       
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
...

private void initVertexArray(GL2 gl)    {
        vertexData = GLBuffers.newDirectFloatBuffer(triangleNumber*3*3);
      for(int i=0; i<triangleNumber; i++) {
          Triangle tmp = triangleArray.get(i);
          vertexData.put(new float[]{tmp.x1/12000.0f, tmp.y1/12000.0f, tmp.z1/12000.0f,
                                     tmp.x2/12000.0f, tmp.y2/12000.0f, tmp.z2/12000.0f,
                                     tmp.x3/12000.0f, tmp.y3/12000.0f, tmp.z3/12000.0f  });
      }
        vertexData.flip();
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #41 - Posted 2011-12-21 16:58:25 »

Solved, I copy here for other ppl, it was hard to find a simple example (just one array, no interleaved) that show the basics

I hope this gets you started, even with more complex setups: introduction to vertex arrays and vertex buffer objects opengl

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline elect

Junior Member





« Reply #42 - Posted 2011-12-21 17:25:05 »

Solved, I copy here for other ppl, it was hard to find a simple example (just one array, no interleaved) that show the basics

I hope this gets you started, even with more complex setups: introduction to vertex arrays and vertex buffer objects opengl

Very cool! thanks Riven  Wink
Offline elect

Junior Member





« Reply #43 - Posted 2011-12-22 09:33:09 »

I didnt found anything about using a single normal vector per triangle with VBOs


..do you know if it is possible?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #44 - Posted 2011-12-22 10:00:45 »

I didnt found anything about using a single normal vector per triangle with VBOs


..do you know if it is possible?
This is impossible. All attributes (colors, texcoords, normals, etc) are specified per vertex, not per triangle.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline elect

Junior Member





« Reply #45 - Posted 2011-12-22 10:12:52 »

I didnt found anything about using a single normal vector per triangle with VBOs


..do you know if it is possible?
This is impossible. All attributes (colors, texcoords, normals, etc) are specified per vertex, not per triangle.

What a pity, I saw it was pretty easy with glBegin/End and I hoped it could somehow possible also with VBOs..

However, I am now exploring the advantages of an indexed VBOs (based on your previous tutorial link). It looks very cool because you can for sure make your vertex array much more compact (and since I am experiencing problem over 2M buffers..)

The only "problem" seems to be the index creation. I am formulating just very roughly (i guess) method, like scanning the whole array, looking for duplicate vertexs, removing one of them and then write in the index array the indexed vertex order..

do you have any good link also for this? Cheesy
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #46 - Posted 2011-12-22 10:31:43 »

You can make something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
class Vec3 {
   public float x,y,z;
   
   @Override
   public int hashCode() {
      int hash = 0;
      hash |= Float.floatToRawIntBits(this.x) * 1;
      hash |= Float.floatToRawIntBits(this.y) * 17;
      hash |= Float.floatToRawIntBits(this.z) * 37;
      return hash;
   }

   @Override
   public boolean equals(Object obj) {
      Vec3 that = (Vec3) obj;
      return this.x==that.x && this.y==that.y && this.z==that.z;
   }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
class Vertex {
   public Vec3 pos;
   public Vec3 color;
   public Vec3 normal;

   @Override
   public int hashCode() {
      int hash = 0;
      hash |= this.pos.hashCode() * 1;
      hash |= this.color.hashCode() * 17;
      hash |= this.normal.hashCode() * 37;
      return hash;
   }

   @Override
   public boolean equals(Object obj) {
      Vertex that = (Vertex) obj;
      return this.pos.equals(that.pos) && this.color.equals(that.color) && this.normal.equals(that.normal);
   }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
class Builder {
   private fianl Map<Vertex, Integer> vertexToIndex = new HashMap<Vertex, Index>();
   private final List<Vertex> vertexList = new ArrayList<Vertex>();

   public int add(Vec3 pos, Vec3 color, Vec3 normal) {
     Vertex v = new Vertex(pos, color, normal);
     Integer index = this.vertexToIndex.get(v);
     if(index == null) {
        this.vertexToIndex.put(v, index=Integer.valueOf(this.vertexToIndex.size()));
        this.vertexList.add(v);
     }
     return index.intValue();
   }

   public List<Vertex> getData() {
       return this.vertexList;
   }
}


I wrote this in the reply, so it might have compile errors.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline elect

Junior Member





« Reply #47 - Posted 2011-12-22 10:36:00 »

You can make something like this:
...
I wrote this in the reply, so it might have compile errors.

Hashes obvious, cool! Thanks Riven Wink


But I have a question: how can you interleave vertexs and normal vectors with an indexed array?

I mean, since every vertex has his own normal (at the moment I am just rewriting the normal vector for the i-th triangle three times, once for each vertex), at the end how you can establish which normal vector assign to a vertex that is shared by two or more triangles?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #48 - Posted 2011-12-22 10:42:32 »

Impossible. An index refers to a set of pos/color/normal.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #49 - Posted 2011-12-22 10:43:06 »

You don't; each normal is duplicated, not shared. A vertex is specified in its entirety by the complete set of its data: coordinate, normal, texcoords, colour, etc. The whole lot is reference by a single index.

If you thought that wasn't the case when using glBegin()/glEnd(), you are mistaken - it is an illusion. glVertex() commands inside a glBegin()/glEnd() actually copied the last specified colour/texture/normal for you behind the scenes.

Cas Smiley

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #50 - Posted 2011-12-22 10:51:41 »

It's probably worth noting that except for certain pathological edge cases (a box being the most common one) you very rarely want to share vertex positions but not normals. For any 'normal' model like your bunny it only really comes up at crease edges, and those will be a tiny fraction of your total vertices.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline theagentd
« Reply #51 - Posted 2011-12-22 12:07:05 »

Also note that aggressive indexing like removing duplicates in models e.t.c. may REDUCE performance, due to the data not being linearly laid out. I found it better to just keep duplicates of vertices in many cases.

Myomyomyo.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #52 - Posted 2011-12-22 12:48:01 »

True, but you can optimize the layout of your data to fully utilize the vertex cache (non-trivial calculation). With a near-perfect solution you can calculate it in O(n).

This can be slightly faster in the general case, and much faster if you have a heavy vertex shader. If most of the vertices are unique, the level of indirection will indeed hurt performance.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline theagentd
« Reply #53 - Posted 2011-12-22 12:59:47 »

True, but you can optimize the layout of your data to fully utilize the vertex cache (non-trivial calculation). With a near-perfect solution you can calculate it in O(n).

This can be slightly faster in the general case, and much faster if you have a heavy vertex shader. If most of the vertices are unique, the level of indirection will indeed hurt performance.
In a small test I made, I had vertices that were each used in 4 to 8 different triangles (average around 7), and it was faster to make all of them unique even if that gave me several times more data to process. Granted, it was impossible to lay out the data in a really effective way.

Myomyomyo.
Offline elect

Junior Member





« Reply #54 - Posted 2011-12-23 09:19:38 »

Here is an example that illustrates perfectly my idea

http://math.hws.edu/graphicsnotes/c2/s4.html

They do an kind of "average" normal vector between two


However, I have the feeling that all of this belongs much more to what should be the tuning part :p so I would leave for the moment all your precious links and comments for later (I am not ironic, seriously)

Focusing back on the core part, after the rapresentation of my model I would need to put a light within the cabin and see where the shadow hits the ground, in terms of space (supposing I surround my model with a circle on the ground, I would need to know how many and how much shadows there are, not only by a graphical view but also by values, i.e: the biggest shadow is 2m long on the circle perimeter in front right side)

Another guy mentioned that since it is (or look) impossible to directly obtain the output from a shader, a solution might be using FBO

I would like to know your considerations about this

Offline elect

Junior Member





« Reply #55 - Posted 2012-01-04 10:05:56 »

I guess I found the right way, another guy suggested me the following:

Quote
One way to do this is to create a FBO (frame buffer object) that has the dimensions of your plane. You'd then set up rendering to go into that FBO instead of the usual application buffers (that are displayed on the screeen) and have your modelview/projection matrices perform the projection of triangles onto the plane. Clear the FBO to white, enable GL_MIN blending (glBlendEquation(GL_MIN)) and render the triangles in black. Then use glReadPixels() to read back the data to main memory or another buffer on the GPU (that buffer could use CUDA/GL interop to be shared with CUDA) depending on where you need to process the information. Black pixels are in shadow, white ones are not.

Then, I decided to opt for a render on a renderBuffer image, attached to my FBO through the Color_attachment (http://www.songho.ca/opengl/gl_fbo.html)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
private void renderShadows(GL2 gl)    {
        //  creating the FBO
       int[] frameBufferID = new int[1];
        gl.glGenBuffers(1, frameBufferID, 0);
       
        // bounding the FBO
       gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBufferID[0]);
       
        // creating the RenderBuffer Object
       int[] renderBufferID = new int[1];
        gl.glGenRenderbuffers(1, renderBufferID, 0);
       
        // bounding the RBO
       gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, renderBufferID[0]);
       
        // Allocate the RBO
       gl.glRenderbufferStorage(GL2.GL_RENDERBUFFER, GL2.GL_RGB, floorWidth, floorHeight);
       
        // Attaching the RB image (RBO) to the FBO
       gl.glFramebufferRenderbuffer(GL2.GL_FRAMEBUFFER, GL2.GL_COLOR_ATTACHMENT0,
                                                GL2.GL_RENDERBUFFER, renderBufferID[0]);
       
        if(gl.glCheckFramebufferStatus(GL2.GL_FRAMEBUFFER) == GL2.GL_FRAMEBUFFER_COMPLETE)
            System.out.println("GL_FRAMEBUFFER_COMPLETE!!");
        else
            System.out.println("..shit ^^");
    }


And so far it works.. I get the confirm that the framebuffer is complete

But I need help, I will start by render a simple triangle, just for testing, but.... what about clearing the FBO to white?? And moreover, what about the pixel format when I am going to read them with glReadPixels()?
Offline elect

Junior Member





« Reply #56 - Posted 2012-01-04 12:01:27 »

I went a little forward

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
// save the current viewport and set the new
       gl.glPushAttrib(GL2.GL_VIEWPORT_BIT);
        gl.glViewport(0, 0, floorWidth, floorHeight);
       
        // bind the FBO
       gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, frameBufferID[0]);
       
        int[] attachmentID = new int[1];
        attachmentID[0] = GL2.GL_COLOR_ATTACHMENT0;
        gl.glDrawBuffers(1, attachmentID, 0);
       
        // clear
       gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
       
        gl.glBlendEquation(GL2.GL_MIN);
       
        gl.glColor3f(0.0f, 0.0f, 0.0f);
       
        // render
       gl.glBegin(GL2.GL_TRIANGLES);
            gl.glVertex3f(0.0f, 1.0f, 0.0f);
            gl.glVertex3f(1.0f, 0.0f, 0.0f);
            gl.glVertex3f(0.0f, 0.0f, 0.0f);
        gl.glEnd();
       
        gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
        gl.glReadBuffer(GL2.GL_BACK);
        gl.glDrawBuffer(GL2.GL_BACK);
       
        //  restore viewport
       gl.glPopAttrib();


I really would like to check by myself the FBO... how can I render it on the screen?
Offline elect

Junior Member





« Reply #57 - Posted 2012-01-04 12:38:21 »

At the moment I am trying to render it using:

1  
2  
3  
4  
5  
gl.glBindFramebuffer( GL2.GL_FRAMEBUFFER, frameBufferID[0] );
        gl.glDrawBuffer(GL2.GL_COLOR_ATTACHMENT0);
        gl.glViewport( 0, 0, floorWidth, floorHeight );
        //gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
       gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT );


but it doesnt work, it doesnt display anything >.>
Offline theagentd
« Reply #58 - Posted 2012-01-04 13:00:49 »

You're not drawing to the screen, so why would it display anything? >_>

Myomyomyo.
Offline elect

Junior Member





« Reply #59 - Posted 2012-01-04 13:33:40 »

You're not drawing to the screen, so why would it display anything? >_>

How can I do to render on the screen the content of a framebuffer?
Pages: 1 [2] 3
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

UprightPath (20 views)
2014-09-21 14:14:06

BurntPizza (26 views)
2014-09-19 21:14:18

Dwinin (40 views)
2014-09-13 03:08:26

Norakomi (70 views)
2014-09-11 07:57:51

TehJavaDev (95 views)
2014-09-11 00:39:09

Tekkerue (49 views)
2014-09-09 20:24:56

mitcheeb (70 views)
2014-09-09 00:06:29

BurntPizza (52 views)
2014-09-07 19:13:42

Longarmx (39 views)
2014-09-07 19:12:14

Longarmx (45 views)
2014-09-07 19:11:22
List of Learning Resources
by Longor1996
2014-08-17 04:40:00

List of Learning Resources
by SilverTiger
2014-08-06 13:33:27

Resources for WIP games
by CogWheelz
2014-08-02 10:20:17

Resources for WIP games
by CogWheelz
2014-08-02 10:19:50

List of Learning Resources
by SilverTiger
2014-08-01 10:29:50

List of Learning Resources
by SilverTiger
2014-08-01 10:26:06

List of Learning Resources
by SilverTiger
2014-08-01 05:54:12

HotSpot Options
by dleskov
2014-07-08 19:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!