当我尝试在lwjgl 3上关注ThinMatrix OpenGL教程但是在运行用于测试索引的代码时,在glDrawElement()函数上返回EXCEPTION_ACCESS_VIOLATION。
错误代码
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000073eb7436, pid=5024, tid=0x0000000000001460
#
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [nvoglv64.DLL+0xab7436]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/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 (0x000000001df25800): JavaThread "MainThread" [_thread_in_native, id=5216, stack(0x000000001ebd0000,0x000000001ecd0000)]
siginfo: ExceptionCode=0xc0000005, reading address 0x0000000000000005
Registers:
RAX=0x0000000000000006, RBX=0x0000000000000000, RCX=0x00014dcd46f1a00a, RDX=0x000000898dd4c83f
RSP=0x000000001eccf000, RBP=0x0000000000000006, RSI=0x0000000020210080, RDI=0x0000000020210080
R8 =0x000000000000009a, R9 =0x0000000000000000, R10=0x0000000000000001, R11=0x0000000075a3b4a0
R12=0x0000000000000000, R13=0x0000000020210828, R14=0x0000000000001401, R15=0x0000000000000000
RIP=0x0000000073eb7436, EFLAGS=0x0000000000010246
Top of Stack: (sp=0x000000001eccf000)
0x000000001eccf000: 0000000000000004 000000001df25800
0x000000001eccf010: 0000000000000000 000000001eccf208
0x000000001eccf020: 0000000000000000 0000000000000000
0x000000001eccf030: 000000001eccf000 0000000000000000
0x000000001eccf040: 0000000000000000 00007ff83b9cd8c0
0x000000001eccf050: 0000000000000004 0000000000000006
0x000000001eccf060: 000000001b9bb240 0000000000001401
0x000000001eccf070: 000000001b9ce478 0000000000000000
0x000000001eccf080: 0000000000000000 0000000073b8bb06
0x000000001eccf090: 0000000020210828 0000000000000004
0x000000001eccf0a0: 0000000020210080 000000001de03770
0x000000001eccf0b0: 0000000000000006 0000000000000006
0x000000001eccf0c0: 0000000000000000 0000000000000000
0x000000001eccf0d0: 000000001b9bb200 000000001df25800
0x000000001eccf0e0: 000000001b9ce478 00000000024e77a6
0x000000001eccf0f0: 000000001df25800 000000001eccf208
Instructions: (pc=0x0000000073eb7436)
0x0000000073eb7416: 0f b7 f8 0f b7 c1 eb 36 41 81 fe 01 14 00 00 0f
0x0000000073eb7426: 85 2c 03 00 00 48 8b 9c 24 c0 00 00 00 48 63 c5
0x0000000073eb7436: 0f b6 54 18 ff 44 0f b6 03 44 3a c2 8b ca 41 0f
0x0000000073eb7446: 47 c8 0f b6 f9 8b ca 41 0f 42 c8 0f b6 c1 2b f8
Register to memory mapping:
RAX=0x0000000000000006 is an unknown value
RBX=0x0000000000000000 is an unknown value
RCX=0x00014dcd46f1a00a is an unknown value
RDX=0x000000898dd4c83f is an unknown value
RSP=0x000000001eccf000 is pointing into the stack for thread: 0x000000001df25800
RBP=0x0000000000000006 is an unknown value
RSI=0x0000000020210080 is an unknown value
RDI=0x0000000020210080 is an unknown value
R8 =0x000000000000009a is an unknown value
R9 =0x0000000000000000 is an unknown value
R10=0x0000000000000001 is an unknown value
R11=0x0000000075a3b4a0 is an unknown value
R12=0x0000000000000000 is an unknown value
R13=0x0000000020210828 is an unknown value
R14=0x0000000000001401 is an unknown value
R15=0x0000000000000000 is an unknown value
Stack: [0x000000001ebd0000,0x000000001ecd0000], sp=0x000000001eccf000, free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [nvoglv64.DLL+0xab7436]
C [nvoglv64.DLL+0x78bb06]
C 0x00000000024e7914
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.lwjgl.system.JNI.callPV(JIIIJ)V+0
j org.lwjgl.opengl.GL11.nglDrawElements(IIIJ)V+14
j org.lwjgl.opengl.GL11.glDrawElements(IIIJ)V+17
j ms.renderer.Renderer.renderer(Lms/renderer/BasicVertex;)V+20
j ms.main.MineSmooth.run()V+143
j java.lang.Thread.run()V+11
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x0000000002300800 JavaThread "DestroyJavaVM" [_thread_blocked, id=2672, stack(0x0000000002170000,0x0000000002270000)]
=>0x000000001df25800 JavaThread "MainThread" [_thread_in_native, id=5216, stack(0x000000001ebd0000,0x000000001ecd0000)]
0x000000001de96800 JavaThread "Service Thread" daemon [_thread_blocked, id=6372, stack(0x000000001e9d0000,0x000000001ead0000)]
0x000000001de14800 JavaThread "C1 CompilerThread3" daemon [_thread_blocked, id=6324, stack(0x000000001e8d0000,0x000000001e9d0000)]
0x000000001de08000 JavaThread "C2 CompilerThread2" daemon [_thread_blocked, id=2936, stack(0x000000001e7d0000,0x000000001e8d0000)]
0x000000001de00800 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=9800, stack(0x000000001e6d0000,0x000000001e7d0000)]
0x000000001ddfc800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=5268, stack(0x000000001e5d0000,0x000000001e6d0000)]
0x000000001ddf7800 JavaThread "Attach Listener" daemon [_thread_blocked, id=8176, stack(0x000000001e4d0000,0x000000001e5d0000)]
0x000000001bf1e800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=6508, stack(0x000000001e3d0000,0x000000001e4d0000)]
0x00000000023f9000 JavaThread "Finalizer" daemon [_thread_blocked, id=6072, stack(0x000000001e1d0000,0x000000001e2d0000)]
0x00000000023f8000 JavaThread "Reference Handler" daemon [_thread_blocked, id=9308, stack(0x000000001dcd0000,0x000000001ddd0000)]
Other Threads:
0x000000001bf09000 VMThread [stack: 0x000000001dbd0000,0x000000001dcd0000] [id=3876]
0x000000001deb1000 WatcherThread [stack: 0x000000001ead0000,0x000000001ebd0000] [id=1512]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap:
PSYoungGen total 76288K, used 14593K [0x000000076b300000, 0x0000000770800000, 0x00000007c0000000)
eden space 65536K, 22% used [0x000000076b300000,0x000000076c1407d8,0x000000076f300000)
from space 10752K, 0% used [0x000000076fd80000,0x000000076fd80000,0x0000000770800000)
to space 10752K, 0% used [0x000000076f300000,0x000000076f300000,0x000000076fd80000)
ParOldGen total 175104K, used 0K [0x00000006c1800000, 0x00000006cc300000, 0x000000076b300000)
object space 175104K, 0% used [0x00000006c1800000,0x00000006c1800000,0x00000006cc300000)
Metaspace used 8247K, capacity 8485K, committed 8832K, reserved 1056768K
class space used 702K, capacity 771K, committed 896K, reserved 1048576K
Card table byte_map: [0x0000000011890000,0x0000000012090000] byte_map_base: 0x000000000e284000
Marking Bits: (ParMarkBitMap*) 0x000000007602a6d0
Begin Bits: [0x0000000012de0000, 0x0000000016d80000)
End Bits: [0x0000000016d80000, 0x000000001ad20000)
Polling page: 0x0000000000a20000
CodeCache: size=245760Kb used=2281Kb max_used=2281Kb free=243478Kb
bounds [0x00000000024d0000, 0x0000000002740000, 0x00000000114d0000]
total_blobs=1236 nmethods=463 adapters=687
compilation: enabled
Compilation events (10 events):
Event: 1.025 Thread 0x000000001de14800 459 s 3 java.util.Vector::addElement (38 bytes)
Event: 1.026 Thread 0x000000001de14800 nmethod 459 0x00000000027095d0 code [0x0000000002709760, 0x0000000002709c88]
Event: 1.028 Thread 0x000000001de14800 460 3 java.util.zip.ZipFile$ZipFileInflaterInputStream::fill (80 bytes)
Event: 1.028 Thread 0x000000001de14800 nmethod 460 0x0000000002709e90 code [0x000000000270a020, 0x000000000270a408]
Event: 1.028 Thread 0x000000001de14800 461 ! 3 java.util.zip.Inflater::setInput (74 bytes)
Event: 1.029 Thread 0x000000001de14800 nmethod 461 0x000000000270a5d0 code [0x000000000270a760, 0x000000000270ac98]
Event: 1.029 Thread 0x000000001de14800 462 3 java.net.URL::toString (5 bytes)
Event: 1.029 Thread 0x000000001de14800 nmethod 462 0x000000000270ae90 code [0x000000000270b000, 0x000000000270b2e8]
Event: 1.029 Thread 0x000000001de14800 463 3 java.net.URL::toExternalForm (9 bytes)
Event: 1.029 Thread 0x000000001de14800 nmethod 463 0x000000000270b3d0 code [0x000000000270b540, 0x000000000270b768]
GC Heap History (0 events):
No events
Deoptimization events (0 events):
No events
Internal exceptions (8 events):
Event: 0.032 Thread 0x0000000002300800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class; name or signature does not match> (0x000000076b307cc0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\sŽ+8Î\O ?
Event: 0.032 Thread 0x0000000002300800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.prefetchRead(Ljava/lang/Object;J)V name or signature does not match> (0x000000076b307fa8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\„•!‡§Ã?
Event: 0.149 Thread 0x000000001df25800 Exception <a 'java/lang/NoSuchFieldError': method resolution failed> (0x000000076b8234c8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\methodHandles.cpp, line 1146]
Event: 0.150 Thread 0x000000001df25800 Exception <a 'java/lang/NoSuchFieldError': method resolution failed> (0x000000076b830a30) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\methodHandles.cpp, line 1146]
Event: 0.180 Thread 0x000000001df25800 Exception <a 'java/security/PrivilegedActionException'> (0x000000076b8db118) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\jvm.cpp, line 1386]
Event: 0.180 Thread 0x000000001df25800 Exception <a 'java/security/PrivilegedActionException'> (0x000000076b8db510) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\jvm.cpp, line 1386]
Event: 0.181 Thread 0x000000001df25800 Exception <a 'java/security/PrivilegedActionException'> (0x000000076b8df528) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\jvm.cpp, line 1386]
Event: 0.181 Thread 0x000000001df25800 Exception <a 'java/security/PrivilegedActionException'> (0x000000076b8df920) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\jvm.cpp, line 1386]
Events (10 events):
Event: 1.032 loading class org/lwjgl/opengl/NVVertexBufferUnifiedMemory
Event: 1.032 loading class org/lwjgl/opengl/NVVertexBufferUnifiedMemory done
Event: 1.033 loading class org/lwjgl/opengl/NVXConditionalRender
Event: 1.033 loading class org/lwjgl/opengl/NVXConditionalRender done
Event: 1.034 loading class ms/utils/Buffers
Event: 1.034 loading class ms/utils/Buffers done
Event: 1.035 loading class org/lwjgl/opengl/GLChecks
Event: 1.035 loading class org/lwjgl/opengl/GLChecks done
Event: 1.035 loading class ms/renderer/BasicVertex
Event: 1.035 loading class ms/renderer/BasicVertex done
Dynamic libraries:
0x00007ff7c0720000 - 0x00007ff7c0757000 C:\Program Files\Java\jre1.8.0_101\bin\javaw.exe
0x00007ff852330000 - 0x00007ff8524f1000 C:\WINDOWS\SYSTEM32\ntdll.dll
0x00007ff851250000 - 0x00007ff8512fd000 C:\WINDOWS\system32\KERNEL32.DLL
0x00007ff84f540000 - 0x00007ff84f728000 C:\WINDOWS\system32\KERNELBASE.dll
0x00007ff851fe0000 - 0x00007ff852087000 C:\WINDOWS\system32\ADVAPI32.dll
0x00007ff8515b0000 - 0x00007ff85164d000 C:\WINDOWS\system32\msvcrt.dll
0x00007ff851be0000 - 0x00007ff851c3b000 C:\WINDOWS\system32\sechost.dll
0x00007ff851650000 - 0x00007ff85176c000 C:\WINDOWS\system32\RPCRT4.dll
0x00007ff8519f0000 - 0x00007ff851b46000 C:\WINDOWS\system32\USER32.dll
0x00007ff852140000 - 0x00007ff8522c6000 C:\WINDOWS\system32\GDI32.dll
0x00007ff848700000 - 0x00007ff848974000 C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.10586.494_none_a2d8b04ea53e3145\COMCTL32.dll
0x00007ff851c40000 - 0x00007ff851ebd000 C:\WINDOWS\system32\combase.dll
0x00007ff84eb00000 - 0x00007ff84eb6a000 C:\WINDOWS\system32\bcryptPrimitives.dll
0x00007ff852100000 - 0x00007ff85213b000 C:\WINDOWS\system32\IMM32.DLL
0x0000000075570000 - 0x0000000075642000 C:\Program Files\Java\jre1.8.0_101\bin\msvcr100.dll
0x0000000075810000 - 0x00000000760aa000 C:\Program Files\Java\jre1.8.0_101\bin\server\jvm.dll
0x00007ff851ec0000 - 0x00007ff851ec8000 C:\WINDOWS\system32\PSAPI.DLL
0x00007ff848be0000 - 0x00007ff848be9000 C:\WINDOWS\SYSTEM32\WSOCK32.dll
0x00007ff84c300000 - 0x00007ff84c323000 C:\WINDOWS\SYSTEM32\WINMM.dll
0x00007ff84a420000 - 0x00007ff84a42a000 C:\WINDOWS\SYSTEM32\VERSION.dll
0x00007ff851b70000 - 0x00007ff851bdb000 C:\WINDOWS\system32\WS2_32.dll
0x0000000000970000 - 0x000000000099c000 C:\WINDOWS\SYSTEM32\WINMMBASE.dll
0x00007ff84f4d0000 - 0x00007ff84f513000 C:\WINDOWS\system32\cfgmgr32.dll
0x0000000075720000 - 0x000000007572f000 C:\Program Files\Java\jre1.8.0_101\bin\verify.dll
0x00000000756f0000 - 0x0000000075719000 C:\Program Files\Java\jre1.8.0_101\bin\java.dll
0x00000000756d0000 - 0x00000000756e6000 C:\Program Files\Java\jre1.8.0_101\bin\zip.dll
0x00007ff84f7a0000 - 0x00007ff850cfc000 C:\WINDOWS\system32\SHELL32.dll
0x00007ff84ee80000 - 0x00007ff84f4c5000 C:\WINDOWS\system32\windows.storage.dll
0x00007ff851ed0000 - 0x00007ff851f22000 C:\WINDOWS\system32\shlwapi.dll
0x00007ff84e950000 - 0x00007ff84e95f000 C:\WINDOWS\system32\kernel.appcore.dll
0x00007ff84e9e0000 - 0x00007ff84ea95000 C:\WINDOWS\system32\shcore.dll
0x00007ff84e990000 - 0x00007ff84e9db000 C:\WINDOWS\system32\powrprof.dll
0x00007ff84e970000 - 0x00007ff84e984000 C:\WINDOWS\system32\profapi.dll
0x00007ff83b980000 - 0x00007ff83ba4e000 A:\Java Programming\Library\LWJGL 3\native\lwjgl.dll
0x00007ff851460000 - 0x00007ff8515a3000 C:\WINDOWS\system32\ole32.dll
0x00007ff84e3f0000 - 0x00007ff84e3fb000 C:\WINDOWS\SYSTEM32\CRYPTBASE.DLL
0x00007ff847070000 - 0x00007ff8470ac000 A:\Java Programming\Library\LWJGL 3\native\glfw.dll
0x00007ff84d180000 - 0x00007ff84d216000 C:\WINDOWS\system32\uxtheme.dll
0x00007ff846870000 - 0x00007ff8468b1000 C:\WINDOWS\SYSTEM32\dinput8.dll
0x00007ff8489b0000 - 0x00007ff8489be000 C:\WINDOWS\SYSTEM32\xinput1_4.dll
0x00007ff84d150000 - 0x00007ff84d177000 C:\WINDOWS\SYSTEM32\DEVOBJ.dll
0x00007ff84bb10000 - 0x00007ff84bb32000 C:\WINDOWS\SYSTEM32\dwmapi.dll
0x00007ff834340000 - 0x00007ff834469000 C:\WINDOWS\SYSTEM32\opengl32.dll
0x00007ff846de0000 - 0x00007ff846e0e000 C:\WINDOWS\SYSTEM32\GLU32.dll
0x00007ff837480000 - 0x00007ff83757a000 C:\WINDOWS\SYSTEM32\DDRAW.dll
0x00007ff848980000 - 0x00007ff848988000 C:\WINDOWS\SYSTEM32\DCIMAN32.dll
0x00007ff84d710000 - 0x00007ff84d71c000 C:\WINDOWS\SYSTEM32\HID.DLL
0x00007ff850e10000 - 0x00007ff851239000 C:\WINDOWS\system32\SETUPAPI.DLL
0x00007ff84eaa0000 - 0x00007ff84eaf5000 C:\WINDOWS\system32\WINTRUST.dll
0x00007ff84e960000 - 0x00007ff84e970000 C:\WINDOWS\system32\MSASN1.dll
0x00007ff84eb70000 - 0x00007ff84ed38000 C:\WINDOWS\system32\CRYPT32.dll
0x00007ff8452c0000 - 0x00007ff845305000 C:\WINDOWS\SYSTEM32\vulkan-1.dll
0x00007ff8341b0000 - 0x00007ff83433c000 C:\WINDOWS\SYSTEM32\Dbghelp.dll
0x00007ff84de40000 - 0x00007ff84de71000 C:\WINDOWS\SYSTEM32\ntmarta.dll
0x00007ff851300000 - 0x00007ff85145a000 C:\WINDOWS\system32\MSCTF.dll
0x0000000073400000 - 0x0000000075570000 C:\WINDOWS\SYSTEM32\nvoglv64.DLL
0x00007ff84b710000 - 0x00007ff84b723000 C:\WINDOWS\SYSTEM32\WTSAPI32.dll
0x00007ff84e430000 - 0x00007ff84e486000 C:\WINDOWS\SYSTEM32\WINSTA.dll
VM Arguments:
jvm_args: -Djava.library.path=A:\Java Programming\Library\LWJGL 3\native -Dfile.encoding=Cp1252
java_command: ms.main.MineSmooth
java_class_path (initial): A:\Java Programming\Game\MineSmooth Engien\bin;A:\Java Programming\Library\LWJGL 3\jar\lwjgl.jar
Launcher Type: SUN_STANDARD
Environment Variables:
PATH=C:/Program Files/Java/jre1.8.0_101/bin/server;C:/Program Files/Java/jre1.8.0_101/bin;C:/Program Files/Java/jre1.8.0_101/lib/amd64;A:\C++ Programming\Library\Vulkan 1.0.21.1\Bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Autodesk Shared\;C:\Users\ottet\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Git\cmd;"C:\Program Files\Java\jdk1.8.0_101\bin";C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\ottet\AppData\Roaming\npm;C:\Docfa4\PGM;C:\WINDOWS\System32;
USERNAME=ottet
OS=Windows_NT
PROCESSOR_IDENTIFIER=AMD64 Family 21 Model 2 Stepping 0, AuthenticAMD
--------------- S Y S T E M ---------------
OS: Windows 10.0 , 64 bit Build 10586 (10.0.10586.0)
CPU:total 8 (8 cores per cpu, 1 threads per core) family 21 model 2 stepping 0, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, aes, clmul, mmxext, 3dnowpref, lzcnt, sse4a, tsc, tscinvbit, tscinv, bmi1
Memory: 4k page, physical 16675024k(13021908k free), swap 19165392k(15118524k free)
vm_info: Java HotSpot(TM) 64-Bit Server VM (25.101-b13) for windows-amd64 JRE (1.8.0_101-b13), built on Jun 22 2016 01:21:29 by "java_re" with MS VC++ 10.0 (VS2010)
time: Mon Sep 05 20:19:13 2016
elapsed time: 1 seconds (0d 0h 0m 1s)
我已经简化了代码,也许这个错误更加明显:
EDITED
VertexArrayObject
package ms.renderer;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import ms.utils.Buffers;
public class VertexArrayObject {
private int vaoID;
private int vboID;
private int indexID;
private int vertexCount;
public VertexArrayObject() {
}
public void init() {
float[] positions = new float[]{
-0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
};
int[] indices = new int[]{
0, 1, 3, 3, 1, 2
};
vertexCount = indices.length;
vaoID = glGenVertexArrays();
glBindVertexArray(vaoID);
vboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, Buffers.createFloatBuffer(positions), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
indexID = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, Buffers.createIntBuffer(indices), GL_STATIC_DRAW);
}
public void render() {
glBindVertexArray(vaoID);
glEnableVertexAttribArray(0);
glDrawElements(GL_TRIANGLES, vertexCount, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glBindVertexArray(0);
}
public void cleanUp() {
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDeleteBuffers(vboID);
glDeleteBuffers(indexID);
glBindVertexArray(0);
glDeleteVertexArrays(vaoID);
}
}
MainClass
package ms.main;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL.*;
import static org.lwjgl.opengl.GL11.*;
import ms.input.KeyboardInput;
import ms.renderer.VertexArrayObject;
import ms.utils.FinalVariables;
public class MainClass implements Runnable {
private Thread thread;
private static Display display = new Display();
private static VertexArrayObject render = new VertexArrayObject();
private static int WIDTH = FinalVariables.WIDTH;
private static int HEIGHT = FinalVariables.HEIGHT;
private static String TITLE = FinalVariables.TITLE;
private boolean isRunning = false;
public static void main(String[] args) {
MainClass game = new MainClass();
display = new Display(WIDTH, HEIGHT, TITLE);
game.start();
}
public void start() {
isRunning = true;
thread = new Thread(this, "MainThread");
thread.start();
}
public void run() {
display.init();
createCapabilities();
display.libVersion();
render.init();
while(isRunning) {
update();
render();
render.render();
if(glfwWindowShouldClose(display.window)) {
isRunning = false;
}
}
render.cleanUp();
}
public void update() {
if(KeyboardInput.isKeyDown(GLFW_KEY_ESCAPE)) {
isRunning = false;
}
glfwPollEvents();
}
public void render() {
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
glfwSwapBuffers(display.window);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
}
缓冲器
package ms.utils;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
public class Buffers {
public static ByteBuffer createByteBuffer(byte[] data) {
ByteBuffer buffer = ByteBuffer.allocateDirect(data.length).order(ByteOrder.nativeOrder());
buffer.put(data);
buffer.flip();
return buffer;
}
public static FloatBuffer createFloatBuffer(float[] data) {
FloatBuffer buffer = ByteBuffer.allocateDirect(data.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
buffer.put(data);
buffer.flip();
return buffer;
}
public static IntBuffer createIntBuffer(int[] data) {
IntBuffer buffer = ByteBuffer.allocateDirect(data.length << 2).order(ByteOrder.nativeOrder()).asIntBuffer();
buffer.put(data);
buffer.flip();
return buffer;
}
}
答案 0 :(得分:1)
我没有在代码中读得很远,但是一个问题很快就会跳出来。您使用int
作为索引类型:
int[] indices = {
0, 1, 3,
3, 1, 2
};
但是,在绘图调用中,您将索引类型指定为GL_UNSIGNED_BYTE
:
glDrawElements(GL_TRIANGLES, vertex.getVertexCount(), GL_UNSIGNED_BYTE, 0);
您在此处指定的类型必须与索引的实际类型相匹配。所以它应该是:
glDrawElements(GL_TRIANGLES, vertex.getVertexCount(), GL_UNSIGNED_INT, 0);
另一个问题是,在进行绘制调用时,您没有索引缓冲区绑定。你有这个方法:
private void bindIndicesBuffer(int[] indices) {
int vboID = glGenBuffers();
vbos.add(vboID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, Buffers.createIntBuffer(indices), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
与方法名称所暗示的相反,它不绑定索引缓冲区。嗯,它首先执行,但它在结束时解除绑定,因此当方法完成时索引缓冲区是nob绑定的。只需删除取消绑定索引缓冲区的最后一个调用,以便VAO状态包含正确的GL_ELEMENT_ARRAY_BUFFER
绑定。
答案 1 :(得分:1)
谢谢大家的解释和及时回复,我已经部分地解决了Judison给出的解决方案,但并未完全解决。 通过render方法删除glEnableVertexAttribArray(0)并进行他推荐的所有修改,但是我解决了问题,打开窗口,它没有呈现矩形。问题只是glBindVertexArray位置(0)的事实。因此,解决方案就是将方法移到最后。
<强> VertexArrayObject 强>
package ms.renderer;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import ms.utils.Buffers;
public class VertexArrayObject {
private int vaoID;
private int vboID;
private int indexID;
private int vertexCount;
public VertexArrayObject() {
}
public void init() {
float[] positions = new float[]{
-0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
};
int[] indices = new int[]{
0, 1, 3, 3, 1, 2
};
vertexCount = indices.length;
vaoID = glGenVertexArrays();
glBindVertexArray(vaoID);
vboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, Buffers.createFloatBuffer(positions), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
indexID = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, Buffers.createIntBuffer(indices), GL_STATIC_DRAW);
glBindVertexArray(0);
}
public void render() {
glBindVertexArray(vaoID);
glEnableVertexAttribArray(0);
glDrawElements(GL_TRIANGLES, vertexCount, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glBindVertexArray(0);
}
public void cleanUp() {
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDeleteBuffers(vboID);
glDeleteBuffers(indexID);
glBindVertexArray(0);
glDeleteVertexArrays(vaoID);
}
}
感谢大家给予我的帮助!
答案 2 :(得分:0)
首先,每次进行渲染时都不需要启用vertexAttrib ...
MyListData
其次,不要取消绑定任何缓冲区,你需要ARRAY_BUFFER和ELEMENT_ARRAY_BUFFER都绑定到VAO ... 你可以(必须)取消绑定vao,但缓冲区绑定到vao并且你想让它们保持绑定。
public void render() {
glBindVertexArray(vaoID);
glDrawElements(GL_TRIANGLES, vertexCount, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glBindVertexArray(0);
}
我和你在这里犯了同样的错误,改变了它,然后工作了(红屏)。 希望它有所帮助