Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Hot answers tagged

39

The attenuation function you've got, att = 1.0 / (1.0 + 0.1*dist + 0.01*dist*dist) is a fairly common one in computer graphics - or, more generally, 1.0 / (1.0 + a*dist + b*dist*dist)) for some tweakable parameters a and b. To understand how this curve works it's helpful to play with the parameters interactively. This curve is nice because it approaches ...


20

What you have described is entirely adequate and appropriate to provide resolution independence. Anything you draw will indeed always take up the same proportion of your window. However, if you do nothing more than this, you will have aspect ratio problems. For example, given the numbers you wrote, if you draw a circle, it will be squashed — wider than it ...


19

There are two possible causes for this type of problem, depending on exactly which problem it is. I'll list both: 1. You are seeing other colors from your texture along the edges of the tiles. This looks to me like the problem in this case, because all of the edge pixels are one of three colors which are plausibly in your texture: white, black, and brown. ...


19

Put it wherever you can to make it work. Anything else is design paralysis and just going to slow down your progress. When you start seeing patterns emerge, refactor your code. Lots of people will give you advice about the One True Way to do something, but without a breadth of experience to draw from, you'll just be parroting ideas without a true ...


17

You need to change the texture magnification type, like so: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); Read about glTexParameter.


17

You could use an algorithm that checks near blocks, and varies the probability depending on what is there - but I think it's largely the wrong approach. What you want to be looking at is fractal noise types - in this case, perlin or simplex noise. If you generate noise, you'll get values from -1 to 1. http://en.wikipedia.org/wiki/Perlin_noise You can then ...


13

This is from an old OpenGL-based game engine I was trying to write about seven years ago written in C++ so bare with me as I try to explain how I handled 3D world and 2D GUI rendering operations within it. I used four primary methods within my OpenGL renderer class (OGLRender) of which are: ready3D() for preparing OpenGL to render the 3D world scene. ...


11

There is no such directory; %APPDATA% is Windows-specific. You'll have to abstract it yourself: create your own GetSaveGameDirectory function that returns an appropriate path on whatever operating system you're running on. You can typically make this determination at compile time with preprocessor checks against the appropriate macros in C (and it's ilk). I'...


11

The reason you're limited to power-of-two sizes is due to how video ram works. Note that what you should do is typically make the image the next highest power of two (.e. 512x256), and then just use a portion of that image for your graphics. You'd be setting your UV coordinates to only use a subsection of the image onto whatever triangles you're rendering. ...


10

Pedantic note: There is no such thing in OpenGL as a "Vertex Buffer Object." There are simply Buffer Objects. A buffer object is simply a linear array of GPU memory that you can allocate, fill with data, read from, and use in a variety of ways. One of the things you can do with buffer objects is store vertex data in them and use them as source arrays for ...


10

This will depend a lot on what you want to acomplish and the type of game you have. You would have a 'game world' time that advances based on the cpu clock. Generally at a much faster pace so it can be seen. And you will need to take into account pausing, alt-tabbing and so on. You can also advance it manually such as when the player sleeps, uses some kind ...


9

The best way in my opinion is to write your own parser for .obj exported with Blender or your preferred 3D modeling software. It will really only take you a maximum of one hour and you won't have to worry about distribution/licence issues. Here is a video about this question: http://youtu.be/izKAvSV3qk0.


8

Look at your if statements. You set paused to true, then the next statement evaluates true (because there's no way to not press p for a short enough time and you just set paused to true), and it sets it to false. Try: if(Keyboard.isKeyDown(Keyboard.KEY_P) && !gamePaused) { gamePaused = true; } else if(Keyboard.isKeyDown(Keyboard.KEY_P) &&...


8

The reason you're not finding anything is probably because it's so exceedingly simple there's nothing to ask about and nothing much to talk about. Here's how a day/night cycle works: You have a sun and moon that travel overhead (maybe also stars, etc). Your game has a time of day. The position of the sun and moon, and appearance of the sky, depends on the ...


7

You can't. The nature of any kind of digital data is that once information has been removed it can never be put back, and likewise you can't fill in information that was never there in the first place - the best you can do is a rough approximation, which gives you blurriness. Using GL_NEAREST won't blur but it will become pixellated instead. The solution ...


7

I'm using this code on my game right now: System.getProperty("user.home"); Simple and efficient. It's a user dependent directory, which is perfectly fine for storing save files. I'm using it to download and store assets, though.


7

These can be done using shadow mapping. Basically, place the camera at the light source and render the scene into a depth buffer; the resulting buffer identifies all the lit surfaces since they are just the surfaces the light can "see". This texture is then used in the pixel shaders in the main render to mask away light on surfaces behind the shadow map. ...


7

Instead of me just giving you the classes and you not knowing what is happening in them, I will provide you with an explanation and run down of what is happening and then you can give it a go yourself. I believe it's better to teach someone how to fish rather than catching the fish for them :) Ok so lets get into it! A camera is basically just an x and y ...


7

Unexpectedly black pixels sometimes indicate that you've got an infinity or NaN in the shader somewhere. For example normalize(vec3(0,0,0)) will generate a NaN. To me, the most obvious candidate in the above shader is the reflectDirection variable, but I could be wrong. GLSL has isinf() and isnan() functions that you can use to detect those cases. If that ...


7

LibGDX is based on LWGL and its advantage are that a lot of the base stuff is already written and you don't need to write it. Some people prefer to write it themselves though. LibGDX is generally used in mobile game development, but can also be used on Windows, Mac and Html. Some final words: For beginners I would suggest using LibGDX, because it is easier ...


6

What that code is doing is limiting motion to only if you're inside the screen. What you should instead do is something like this: //control code here if(player.getx() > 1024){ player.setx(1024); }else if(player.getx() < 0){ player.setx(0); } that way if the player exceeds the bounds of the screen the position will be set back to the bounds.


6

If you build your meshes more carefully, ensuring you are reusing vertices wherever possible, you should be fine: That is, you must not duplicate vertices per face as then the GPU rasteriser will see them as two discrete objects and sometimes fail to rasterise the in-between space (thus defaulting to the GL's clear colour) due to floating point limitations; ...


6

I had the same problem with a recent game I'm working on. I guess you are using one big texture with all the block textures in it (like Minecraft does it)? If so these white pixels appear because of rounding errors in the shader that lead to "empty" texture spots. This occurs even if you do not use texture interpolation (which is the case with your game ...


6

The library comes with examples of how to use it. All of the source code for the webstart examples comes with the library. There's also a tutorials section in the wiki page for jBullet. Further, most of the tutorials for the c++ version are applicable to the Java port. You will just need to modify the class and function names to work with the Java syntax ...


6

For small data like this, you want glBufferSubData, sweet and simple :) Later on you probably should look into glMapBuffer though, as it is how you work with data larger than a few kilobytes quickly.


6

The oscillation is a common thing. Likely from CPU scheduling and other processes on the system. The first frame being very long is an error in your code. Consider what lastFrame is set to when the application starts (likely 0), so for the first frame you're just setting deltaTime to the time/1000. You can add a check that if lastFrame is 0, the deltaTime ...


6

gluUnProject(float winx, float winy, float winz, FloatBuffer modelMatrix, FloatBuffer projMatrix, IntBuffer viewport, FloatBuffer obj_pos) winx ,winy and winz are the screen coordinates which you want to transform back to world coordinates. winx and winy are in this case the x and y coordinates of the mouse as returned from Mouse.getX() and Mouse.getY(...


6

You are using sampler2D with a texture that has GL_TEXTURE_COMPARE_MODE != GL_NONE. That is not going to work, you are invoking undefined behavior. This line: GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_COMPARE_MODE, GL30.GL_COMPARE_REF_TO_TEXTURE); Tells OpenGL that when you fetch something from this texture, rather than returning the ...


6

You can try doing this with flat attribute qualifier in shaders, like so: flat vec3 surfColor; It tells GLSL to pass values from vertex to fragment without interpolation. From GLSL Interpolation qualifiers: Interpolation qualifiers control how interpolation of values happens across a triangle or other primitive. There are three basic interpolation ...


5

Well, the simplest way to do it is use a higher-resolution texture, together with a full mip chain, trilinear filtering, and you'll probably want to turn on anisotropic filtering as well; that should give you smooth edges without (as much) over-blurring. Another approach would be to use distance field textures, which are specifically for two-tone images (in ...


Only top voted, non community-wiki answers of a minimum length are eligible