Opengl multiple glDrawArrays calls - java

I have a Problem with vertex array objects in opengl (java, lwjgl).
The Program itself works, i have an object, can move around it.
The draw call is simple:
Gl11.glDrawArrays(drawmode, 0, 4);
In the shader i have one uniform for the model, (called model ^^).
Now i tried the following: (pseudo code)
update the model
draw
update the model
draw again
This doesn't work. why? I know there is instancing, but that isn't my aim here. I just want to draw 2 things with 2 draw calls. But i only see the first one.. does anyone have an idea?
** Edit **
I hate it. I hate this principe... Again and again I forget to flip the buffer before using it in opengl. Now again. That was the point... the first time i flipped it the second time not... I can't get it into my brain to flip this buffers -.-

Related

How to have mutliple methods of the same type? ("Processsing" programming)

all.
I am newer to programming, but headstrong.
I have an assignment for class, in which we have to use the "draw" method (which I understand is just a function, but in Java) and I need to leave a "trail". I already know how to leave a trail, but I want to leave a specific trail (mainly boot prints from my character's shoe). So I decided to write a separate draw method, but I can only use one. Is there any way to write another draw method?
If not, is there a way to leave a "trail" behind the man where I move him?
What I mean by trail: Using the draw method, I create a box that moves with my mouse. The draw command loops over and over, many times a second. However, it doesn't erase the previous draw, so a trail of boxes a left as they are draw out. I just want to have a trail of a specific shape, one that I can define.
Thank you all.
You have three options:
Option 1: Simply don't clear out old frames, by not calling the background() function every time draw() is called. This will cause your old drawings to stick around, which will look like a trail. This will work for simple stuff like circles, but will not work if you want your trail to be different from your drawing, or to do something like fade out over time.
Option 2: Store your trail in some kind of data structure. You might use an ArrayList that contains PVector instances, for example. Then each frame, clear out the old frames by calling background(), and then iterate over the data structure to draw your trail. Then add and remove from that data structure to change the trail over time.
Option 3: Draw your trail to an offscreen buffer. Hint: look up the createGraphics() function in the reference. This is similar to what you were trying to do, but instead of having a second draw() function you would draw the trail to the buffer. Then each frame, you would draw the buffer to the screen, and finally draw the object to the screen.

OpenGL Objects Position and Physics

I have two simple questions:
First question:
Given is an object in OpenGL in an android application.
I want to apply phyics on the object like Gravtiy.
For this I've implemented a Public PositionVector {x,y,z,1.0f};
In the Object Object. So for example: Sphere.PositionVector = {0f,0f,0f,1f}
for the center of screen.
When I do the movement now, I have a modelMatrix and to update the Position should I multiply the modelMatrix with the PositionVector? But then I will still get 0,0,0,1.
mulitplyMV(tempVector,0,modelMatrix,0,PositionVector,0);
Where is the mistake? Or: What is the usual way to do this?
My goal is to have always the current positionvector of the Sphere.
Second question:
Does the shader have to do anything with the physics? Or may I calculate the gravtiy and the resulting vectors in the javaCode and apply then a translateMatrix to the modelMatrix?
Greetings,
Phil
So the first thing that really jumped out at me, was the question about movement. Normally if the movement was only for a visual effect, multiplying your position with a model matrix would be fine, but obviously you'll be wanting to handle collisions and that sort of thing as well.
What I normally do, is I keep track of each objects position, and update that value whenever it moves. When I draw my object, I first do a pass to leave out all objects that aren't in view and then only draw what my camera is seeing. So in this case, you'll only be drawing what is actually visible on the phone's screen at the moment.
So if you have a view matrix for your camera, to keep it simple for now you can leave out view culling, but you'll multiply your objects current position with the model matrix(in this case it is just an identity so it doesn't have any impact), and additionally with the view matrix and projection matrix. So its something like vec3 viewSpacePosition = projectionMatrix * viewMatrix * modelMatrix * position; (assuming I'm remembering that one correctly.)
Your physics calculations can be done either in your shaders or in your java code, though I recommend doing it on the java side while still getting the hang of things. OpenCL and transform feedback buffers can be quite tricky when you're still learning how some of the stuff works.
For the physics portion of your code, I would highly recommend taking a look an Glen Fiedler's series on game physics, you can find it here.
If you have any more questions, or if there is something you're still uncertain of let me know. :) Good luck!

LWJGL - Hide cube face while hidden

I have many problems unsolved, and i'm kind of new at LWJGL.
Here is a screen: http://image.noelshack.com/fichiers/2015/07/1423885261-sans-titre.png
(this is 20x20x20 simple cube)
But as you can see, my fps are not bigger than 40 and every face of the cube is showing. How can i fix the fps drop and hide the hidden block behind another one ?
I have glEnable(GL_DEPTH_TEST); and glEnable(GL_CULL_FACE); but it only work INSIDE the block :x ...
Sorry for my english too but i really need help :p
Culling
If culling only works if you are inside a block your vertex winding order is most likely mixed up. If so you might want to change it from the default GL_CCW to GL_CW or fix your vertex order to the default. Reference here
SpeedUp
For this your question has too few information. If you are not doing so already you might want to switch to using Vertex_Buffer_Object. Preferably using a single geometry that is only translated.
An additional approach would be to only render objects that are in line of sight of the camera. One method for this is a Binary Search Tree

Simple java game: Filling up figures drawn by a moving cursor

So I'm doing the project of an introduction to Java course and it seems that I chose something that goes way beyond what I'm able to do. :P
Any help would be greatly appreciated. This is what I'm having problems with:
You have a cursor that is controlled by a player (goes forward or
turns 90°) which leaves a colored line as it goes. If you manage to go
over your own line and close a polygon of any shape (only right angles
though), its surface changes color into the color of your line.
I can detect when this situation arises but I am kind of lost as how to actually fill the correct polygon just closed. I can't seem to imagine an algorithm that would cover any case possible.
I looked at the Scanline fill algorithm but I think it would start having problems by the time there are already some polygons already filled in the map.
The Floodfill algorithm would be perfect if I had a way of finding a point inside the polygon, but, as there are many different possibilities, I can't think of a general rule for this.
I'm using an array 2x2 of integers where each color is represented by a number.
Does anyone have an idea on how to approach this problem?
If you can detect the situation then this can be solved in very simple manner. The question is which point to choose as start point for floodfill. The simple answer is: try all of them. Of course it makes a sense to start only with points adjacent to the one where your cursor is located. In this case you will have at most 8 points to check. Even better - at least 2 of them are definitely painted already if current point forms a polygon.
So you have 8 points to check. Launch floodfill 8 times starting from each of those points.
Two things which you probably should keep in mind:
You should try filling the area in cloned version of your field in order to be able to get back if floodfill will not find a polygon.
Launching floodfill second time and later you should reuse this cloned version of your field to see whether it was filled there. This will allow you to check every point at most once and this will make your 8 floodfills almost as fast as 1 floodfill.
Check this question, using Graphics2 and Polygon to fill an arbitrary polygon: java swing : Polygon fill color problem
Finding out whether a point is inside or outside a polygon: http://en.wikipedia.org/wiki/Point_in_polygon
Make sure you use double buffering. If you set individual pixels and don't use double buffering the component may redraw after every pixel was set.

How to rotate "Earth" by touching with GLES20 (Android)?

Yesterday I tried to solve a Problem I had the entire Day and it is still unsolved. I searched for every combinations of words I could imagine to find solutions on Google etc. But without success. :(
The Problem consists of following idea:
I started programming GLES20 (Not GLES10!) on Android. There are many other ways how to compute matrixes and objects. So there aren't any methods like "Pop" or "push" Matrix.
I want to rotate a globe/sphere only by touching and moving my fingers. Touching functions etc works fine but the rotation itself never does. Everytime I first rotate by x-axis and then rotating by y-axis the rotation is still computed by local space axis of the object and Not two global axis. This happens whatever I do... :/
There are some people searching the solution for the Same Problem, but mostly GLES10 or completly different programming languages, never GLES20 and Java.
I will also post some Code parts later, when I get access to a Computer.
perhaps someone already understands what my Problem is.
Thank you so much! :)
Chrise
In OpenGL ES 2.0 there aren't any of the matrix functions and you're supposed to take care of your own matrices. So, for pushing and popping matrices what you need to do is when you're drawing you copy your matrix to a temporary one, do whatever transformation on it and pass the temporary matrix to the vertex shader.

Categories

Resources