Show Posts
|
|
Pages: [1] 2
|
|
4
|
Java Game APIs & Engines / OpenGL Development / Re: GLSL and struct arrays
|
on: 2013-04-07 15:58:21
|
|
Hm I see ... arg why is everything so uncomfortable ...
Another followup question: Lets say I have 32 fixed lights. All have a specific position in model space. I have to transform these light coords with the mvpMatrix to get my light calaulations right. It makes absolutly no sense to perform this calculation for every fragment so I wanted to do it once in the vertex shader and then pass it via the positions via an out variable to my fragment shader. Problem is: The amount of "in"-variables in the fragment shader is limited. Much more limited then the amount of uniforms.
Is there a solution to this problem?
|
|
|
|
|
6
|
Java Game APIs & Engines / OpenGL Development / Re: GLSL and struct arrays
|
on: 2013-04-06 18:32:48
|
Wow thanks, I didn't konw that. If I declare a uniform in the fragment shader because I only need it in the fragment shader, do I still have to declare it in vertex shader as well? My test suggests that but it doesn't really makes sense. vertex shader 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #version 140
in vec4 vertex_position; in vec4 vertex_color;
uniform vec2 camera_offset; uniform mat4 mvp_matrix; uniform vec4 color;
out vec4 frag_position; out vec4 frag_colorcode;
void main() { frag_position = vec4(vertex_position.xy - camera_offset.xy, vertex_position.zw) * mvp_matrix; frag_colorcode = vertex_color; gl_Position = frag_position; } |
fragment shader 1 2 3 4 5 6 7 8 9 10 11 12 13
| #version 140 in vec4 frag_position; in vec4 frag_colorcode;
uniform vec4 color; uniform Global_lights[] frag_lights; void main() { gl_FragColor = (color + frag_colorcode); } |
Thanks!
|
|
|
|
|
7
|
Java Game APIs & Engines / OpenGL Development / GLSL and struct arrays
|
on: 2013-04-06 15:11:26
|
Hello, I want to compute multiple lights in my fragment shader. I pass the light data to the vertex shader via a uniform struct[] and then I want to do something like that: 1 2 3 4 5 6 7 8 9 10 11 12 13
| struct Global_lights { ... };
uniform ... uniform Global_lights[] lights;
out ... out Global_lights[] frag_lights;
void pass_lights() { frag_lights = lights; } |
The fragment shader: 1 2 3 4 5 6
| struct Global_lights { ... };
in ... in Global_lights[] frag_lights; |
If I try to compile this I get two errors: Error compiling Shader Vertex shader failed to compile with the following errors: ERROR: 0:27: error(#282) Implicitly sized arrays can not be assigned to ERROR: 0:27: error(#160) Cannot convert from: "uniform array of structure" to: "default out array of structure" ERROR: error(#273) 2 compilation errors. No code generatedI somewhat understand the error message but I'd like some kind of source to read what is allowed and what not. Can someone offer a soluting? The exact amount of lights has to variable. Thanks!
|
|
|
|
|
8
|
Java Game APIs & Engines / OpenGL Development / Re: [LWJGL] Problem with Viewport and Windows Aero vs. Basic
|
on: 2013-03-30 22:13:11
|
I know this comes late, but I finally managed to resolve the problem and for further reference here the solution (that worked for me): For some reason the LWJGL Display bugs out if you issue Display.create(...) before the Display.setResizable(true). So the solution for me was changing 1 2 3 4 5
| Display.setDisplayMode(displayMode); Display.create(pixelFormat); Display.setResizable(resizable); |
to 1 2 3 4 5
| Display.setDisplayMode(displayMode); Display.setResizable(resizable); Display.create(pixelFormat);
|
|
|
|
|
|
10
|
Java Game APIs & Engines / OpenGL Development / Question regarding interaction between VAO bindings and sperate VBO bindings
|
on: 2013-03-24 19:40:36
|
Hello, I've got the following question for you: When I set up my VAO I bind the VAO (glBindVertexArray) then bind the VBO (glBindBuffer(GL_ARRAY_BUFFER)) and IBO (glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)) and then unbind the VAO. As I understand it now the VBO and the IBO are "connected" to the VAO and before I want to draw something I just have to call glBindVertexArray() (without binding the VBO and IBO again). Now, can I bind the VBO / IBO separately (e.g. for calling glBufferSubData()) and don't lose the "connection" between VAO and VBO / IBO (or do I have to go through the hole binding VAO, then VBO/IBO again)? I ask this question because I changed up some code (for optimizing performance) and now I get a 1
| org.lwjgl.opengl.OpenGLException: Cannot use offsets when Element Array Buffer Object is disabled |
I can't quite trace back where the problem is. EDIT: Found the problem that caused the exception (missing glGenBuffers() call ). Question above remains but now I think that I can bind/unbind the VBO/IBO as much as I want without losing the "connection". I'd be very grateful if some could confirm.Thanks!
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Re: Correct way to render thousands of polygons
|
on: 2013-03-20 21:12:34
|
|
Hello,
I'm not sure what you mean by 1) but you will have to issue the following OpenGL calls every frame (assuming you interleave the data and have a single vbo): > Bind the VBO (VAO if you use one - what you should do) > Bind the shader program > Call the GL draw methode (There are quite a few depending on how you set up your VBO / VAO) e.g. glDrawElements(...) > Unbind the program > Unbind the VBO (VAO)
Things you don't have to do and should not do every single frame: > Uploading new/updated data. You should minimize the calls of glBufferData and glBufferSubData
Things you only have to do once: > Compiling/Linking your program > Generating a pointer to your VBO (glGenBuffer)
2) Expensive GL calls are: > Uploading data. Try to use uniforms (e.g. for (offset)-positions) as much as possible > Switching VBOs (binding / unbinding). Try to use very few VBOs. I think 4 MB / VBO is recommended.
Less expensive: > the drawing itself
3) If all the quads (2 triangles) require the same vertex attributes (which I think they do) the pack the triangles in VBOs รก 4 MB. If you are using more than, say, 20 VBOs you are doing something wrong. So I would suggest that one object holds all the tiles which need the same vertex attributes and one VBO (or more if you have a huge number of triangles) for the geometry data.
One of the more experienced members of this form might give you better advice, but thats what I would suggest you to do.
|
|
|
|
|
12
|
Games Center / Cube World Projects / Re: Voxel - a start
|
on: 2013-03-16 20:53:21
|
|
I don't know how much you know about (vertex & fragment) shader but you might want to look into setting positions via a shader uniform rather than modifying the vertex data itself (which is much more expensive). Since you're already useing OpenGL 3.1+ (VBOs) you might as well use shaders as well - if you are not using them already.
The loop would look something like that: 1. use shader program (glUseProgram) and upload the uniform offset (glUseUniform) 2. render the vbo 3. get the next vbo and continue
Of course this only works as described if all vertices share the same offset which should be the case with chunks.
|
|
|
|
|
13
|
Java Game APIs & Engines / OpenGL Development / Re: [LWJGL] Problem with Viewport and Windows Aero vs. Basic
|
on: 2013-03-13 18:47:07
|
Sorry this comes two days late, had lots of work to do. Here some code: glInit (Display) 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
| private void glInitContext() { DisplayMode displayMode = new DisplayMode(main.getWidth(), main.getHeight()); windowDimensions = new int[] { 0, 0, main.getWidth(), main.getHeight() }; PixelFormat pixelFormat = new PixelFormat().withSamples(8); try { Display.setDisplayMode(displayMode); Display.create(pixelFormat); Display.setTitle(title); Display.setResizable(resizable); } catch (LWJGLException e) { e.printStackTrace(); } glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthMask(true); glDepthRange(0.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_MULTISAMPLE); glEnable(GL_SCISSOR_TEST); glViewport(0, 0, Display.getWidth(), Display.getHeight()); glScissor(0, 0, Display.getWidth(), Display.getHeight()); EPHVertexArrayObject.glInitShaderProgramPool(shaderParentPath); glInitialized = true; synchronized (glInitMonitor) { glInitMonitor.notifyAll(); } } |
glDraw (VAO) 1 2 3 4 5 6 7 8 9 10 11 12 13
| public synchronized void glRender() { if (handle < 0 || !updated) glInit(); if (size > 0 && hasVisibleEntries()) { glBindVertexArray(handle); glViewport(viewPortRect[0], viewPortRect[1], viewPortRect[2], viewPortRect[3]); glScissor(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]); glBindVertexArray(0); } } |
I'm not too sure what kind of code you'd like to see ... I thought this are the parts where the viewport is important .
|
|
|
|
|
15
|
Java Game APIs & Engines / OpenGL Development / [LWJGL] Problem with Viewport and Windows Aero vs. Basic
|
on: 2013-03-10 14:26:09
|
Hello, today I used a different PC than I'm usually using for my OpenGL development. On my standard PC I run Win7 with Windows Aero ... everything works just fine. But on this new maschine I get a different result using Viewports: Normal PC / different PC with basic (intended):  different PC with Aero (problem):  It appears that for same reason the glViewport(5, 5, widht, height) gets transformed to glViewport(10, 0, width, height) ... or something like that. I checked the glViewport call and the values are correct but the result stays flawed. Also interesting: as soon as I change the displayMode or manually resize the window the viewport gets applyed correctly. Can someone explain why this problem occurs? Thanks!
|
|
|
|
|
16
|
Game Development / Game Mechanics / Simple Polygon Collision and (!) getting the intersection area
|
on: 2013-03-07 21:58:06
|
Hello, I know there a A LOT of collision threads and tutorials and what not, but after searching for ~1 hour I decided to create yet another thread: I'm familiar with the SAT and (to same degree) PIP (Point in Polygon) algorithms and they're working fine, but I need additional information: I need to know the "line" or set of vectors representing the intersection "cut" area:  I need either the red or the blue edge(part)s (depending on which polygon intersects which) as a set of vectors / lines. I know I can get the minimum translation vector via SAT but I can't come up with or find any ideas that give me what I want. If someone has a link for me or can discribe how to get my intersection cut? Thank you in advance!
|
|
|
|
|
17
|
Java Game APIs & Engines / OpenGL Development / Re: Very small sets of data and VAOs
|
on: 2013-03-06 21:01:30
|
Could you explain what you mean with configuring vertex attributes ? Yes you might be right ... it just somehow bothers me to have such small VAOs as I do .... especially if you look at the recommended size of one VBO ... It doesn't matter with my small application anyway ... thanks for answering though!
|
|
|
|
|
18
|
Java Game APIs & Engines / OpenGL Development / Very small sets of data and VAOs
|
on: 2013-03-06 12:14:41
|
|
Hello,
I've got another question concerning modern OpenGL. In my application I have a few very small (!) sets of vertex data. The vertex attributes are very specific and dont fit in other VAOs I already have. E.g.: I've got 4 vertices and 6 indices (defining 1 quad) for a very specific animated background. As stated the configuration of vertex attributes doesn't really fit the other VAOs and it would be ugly to force it into one of my existing VAOs (e.g. defining unused attributes or making the shadercode and variable naming very nasty). But on the other hand its obviously far from optimal to create a new VAO including a VBO and IBO (with the lots of overhead on the client side as well as the cost of one additional VAO to switch between) either.
How would you suggest to deal with that? Thanks in advance!
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / Questions regarding (VisualVM) profiling
|
on: 2013-03-03 22:57:33
|
Hello, today I tested the VisualVM Profiler on my current project and was quite suprised by the data it gave me. To understand the results I got I have some questions: - Watching the heap memory usage (monitor tab) I observed that my programm's used heap memory steadily increases until it hits ~25 MB used the drops to 3-5 MB within seconds and increases again. Is this normal behavior and why does it happen?
- Watching the thread dispatching I noticed something strange: My gameloop is looping permanently with 1 MS sleep delay build in. I've got no other threads and my console output / fps-data suggests that the loop does what it is supposed to do. But the profiler says my loop-thread sleeps ~75% of the time. I think thats quite contradicting. Can someone explain this?
- The profiler says that a thread called "RMI TCP Connection" allocates A LOT (75%) of data. Also the largest amount of data is char[] ... why?
Thanks in advance!
|
|
|
|
|
21
|
Java Game APIs & Engines / OpenGL Development / Re: Pooling VertexArrayObjects
|
on: 2013-03-02 20:03:07
|
I think you missunderstood me which may be due to my bad english (or just me explaining poorly). I'm perfectly aware that one vao has excatly one vbo and how the binding works. Let me try to explain it a bit more detailed: Lets assume we have 1 vao with 1 vbo and 1 ibo attached to it. The mode of the vao is GL_TRIANGLES and the attributes are 3 vec4 (float). Each frame we bind the vao once. We bind our shader program (and upload uniforms) and use glDrawElements to draw the vbo to the screen. Then we unbind the program and the vao and do other stuff waiting for the next frame. Until now everything should be pretty normal indexed vao rendering. In code: 1 2 3 4 5 6 7 8
| public void render() { vao.glBind(); shaderProgram.glBind(); shaderProgram.uploadUniforms(); glDrawElements(GL_TRIANGLES, vao.size(), GL_UNSIGNED_INT, 0); shaderProgram.glUnbind(); vao.glUnbind(); } |
So here comes my "idea": The only thing set in stone here is the mode (GL_TRIANGLES) and the vertex attributes. Lets introduce "vao entries" represented by an object with specifies a data-section in the vbo and ibo (upper and lower bound). We render these entries using the offset in glDrawElements. It looks something like: 1 2 3 4 5 6 7 8 9 10
| public void render() { vao.glBind(); shaderProgram.glBind(); shaderProgram.uploadUniforms(); for(VAOEntry e : allVAOEntries) { glDrawElements(GL_TRIANGLES, e.upperBound - e.lowerBound, GL_UNSIGNED_INT, e.lowerBound); } shaderProgram.glUnbind(); vao.glUnbind(); } |
Now we render sections of the vao content separately using the same shader program. The last adjustment I make is giving each entry a separate shader program with the condition all shader programs use the same vertex attributes. 1 2 3 4 5 6 7 8 9 10
| public void render() { vao.glBind(); for(VAOEntry e : allVAOEntries) { e.glBindShaderProgram(); e.uploadUniforms(); glDrawElements(GL_TRIANGLES, e.upperBound - e.lowerBound, GL_UNSIGNED_INT, e.lowerBound); e.glUnbindShaderProgram(); } vao.glUnbind(); } |
Now I want to create only one VAO for the most common mode / vertex attrib combination and use entries and different shader programs to store completly different graphic-objects in these vao (but all sharing the same mode and vertex attribs). That minimises the amount of vao drastically as I'm combine "to-draw-objects" in one vao over the "interface" of a common mode and vertex attribs. Hopefully its more comprehensible now.
|
|
|
|
|
22
|
Java Game APIs & Engines / OpenGL Development / Pooling VertexArrayObjects
|
on: 2013-03-02 11:15:59
|
Hello, I'm tinkering around with modern OpenGL (using vaos w/ indexed vbos) and efficient usage of vbos. My (hopefully reasonable) goal is to minimise the amount of vaos and in consequence less switching between vaos (which - as I understand it - is really expensive performancewise). So the main difference between different vaos is the data storage namely the type (GL_POINT, GL_LINE, GL_TRIANGLE) and the attributes (datatype, name, location). I observed that (at least) in my applications certain types of vaos are used very frequently: - [GL_TRIANGLE, (3x4 float Attrib)]
- [GL_TRIANGLE, (4x4 float Attrib)]
- [...]
Currently I have quite a decent amount of different vaos despite an overlap of this distinctive vao characteristic. So I thought about creating exactly one vao for each of these commonly used specifications and applying different shader programs with different uniforms as I need them. In other words: pooling commonly used vao specifications. Possible downsides are: - increased shader program switching
- forcing a standardised shader attrib naming for the pooled vaos and all shader programs I want to use with them
- significant more effort required write the code manageing the pool
- can you point out some more?
Do you think that might work at all? In my applications that would reduce the amount of vaos from ~80 to ~30 vaos which is quite a huge number. Do you think the performance increase is worth the hassle? Thanks in advance!
|
|
|
|
|
23
|
Java Game APIs & Engines / OpenGL Development / (LWJGL) Subdivision of the Display
|
on: 2013-01-22 20:23:39
|
|
Greetings!
I'm currently working on the basics of my lwjgl-project and got the following question: How can I subdivide my Display into different parts? I need something like different clipping-panes for different parts. I think there is something in the fixed-function pipeline but I want to use non-deprecated OpenGL only!
To give you an example: Say, I want to divide my display into two equally big parts (part 1 & 2) (vertically). I then want to render objects of type A to part 1 and objects of type B to part 2. Both should be clipped when crossing the vertical "boarderline".
One possible solution I already tested is simple discarding the fragments out of my imaginary clipping pane via frag-shader. But this seems like a rather ugly solution because I'd have to implement that in every frag-shader and so every object. I'm looking for a better option to to this.
Thank you in advance!
|
|
|
|
|
25
|
Discussions / General Discussions / Re: C++ for Modern OpenGL
|
on: 2013-01-20 19:02:03
|
|
OpenGL is no programming language (its a specification) neither is it "made" for any particular language. Fact is that (the common) implementation(s) for OpenGL are written in C and thereby making it much easier to use these implementations in C / C++ (see the pointer-problem in Java).
The fact that most tools are written for C / C++ is that most applications that make use of OpenGL are traditionally written in C / C++. To use modern OpenGL you need a modern implementation (and a wrapper for it if you cannot use that implementation dircetly). So feel free to use the JNI and the implementation dircetly or choose a modern wrapper framework like LWJGL or JOGL (for java).
|
|
|
|
|
26
|
Game Development / Game Play & Game Design / Penny-Arcade's Show: Extra Credits
|
on: 2013-01-19 21:38:59
|
Hello, I've just spent hours watching this show on the website http://www.penny-arcade.com/ and thought that it might be very useful to at least some of you. I've searched for existing threads but only found one topic mentioning it briefly so I decided to make a thread of my own. Each epsiode of this show picks up a topic concering game design and/or the game industry and explains various things (such as story-design, tutorial-design, getting started in the industry, etc. etc.) . It's very entertaining and informative to watch and doesn't really take much time due to one episode beeing ~6 minutes long. Here is the link: http://www.penny-arcade.com/patv/show/extra-creditsI really encourage you to watch at least one episode. Cheers, greenOwl
|
|
|
|
|
27
|
Game Development / Newbie & Debugging Questions / Re: lwjgl and 2D?
|
on: 2013-01-17 21:42:54
|
A really detailed and well written modern OpenGL tutorial: http://www.arcsynthesis.org/gltut/index.htmlThe client code is written in C but its really easy to port to java because most of the lwjgl methods resemble the calls in the tutorial. I've learned OpenGL with that tutorial (and the orange book for shaders) and I think learing modern techniques like VertexArrayObjects and indexed VertexBufferObjects is really the only way to do it "properly".
|
|
|
|
|
29
|
Java Game APIs & Engines / OpenGL Development / Re: Different shader(programs) for different animations
|
on: 2012-12-31 16:13:56
|
|
I work completely without textures. Some expamples of animations I wrote already: > Change coordiantes of vertices to create all kinds of animation based on modifying the shape of my entity (e.g. modify the coordinates in a circular motion to create a wobbly-effect of my entity. > Use procedural methods in the fragment shader (e.g. noise, gradient-fills, shapes, ...)
Currently I'm just fiddling around with opengl and shaders. I could imagine a total of ~100 objects not counting particles and other effects.
|
|
|
|
|
30
|
Java Game APIs & Engines / OpenGL Development / Re: Different shader(programs) for different animations
|
on: 2012-12-31 15:46:15
|
|
The "interface"-thingy danny02 suggested sounds quite nice. The downside I see with his solution is a lot of shader-initialization (glShaderSource - ... - glLinkProgram) calls each time I want to change the animation and have to remove, attach and recompile the shader. I dont know for certain, but I belive that this is not quite the optimum concerning performance and such.
@pitbuller Yes thats why I really don't want to an entire shader for each animation. What do you suggest instead? 1000+ lines per file seem really uncomfortable as well. That do you mean with "data driven systems"?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|