Tag Info

New answers tagged

0

Just to add some more context to the other excellent answers. The immediate mode as described in the first link is, as others have said, legacy code from the earliest versions of OpenGL (1.1). It was used back when GPUs were little more than triangle rasterizers and the idea of programmable pipelines didn't exist. If you look at the source code for some of ...


0

If you only need 2D you can use OpenVG which is essentially the 2D counterpart of OpenGL. official site: https://www.khronos.org/openvg/ wikipedia: http://en.wikipedia.org/wiki/OpenVG If you need 3D ribbons / lines integrating with a 3D scene you'll have to do line expansion yourself and draw them using a 3D API such as OpenGL or Direct3D. Geometry ...


0

Honestly I don't understand your code. Though I want you to think about a refactoring of it. Since you already have a vector structure (Vector3f - I guess its from lwjgl) why not use it? Vector3f wayTowardPlayer = new Vector3f(); Vector3f.sub(player.getPosition(), this.position, wayTowardPlayer); if (wayTowardPlayer.lengthSquared() > 0) { ...


0

Like @Terje says, the short answer is "Yes, OpenGL can outperform Swing." You've seen modern video games, you know current graphics hardware can do truly amazing things. Pragmatically, what you can do is look at the CPU load of your current "Pong" game, or whatever it is. Based on the CPU percentage, and what your ultimate goal is, maybe Swing is just ...


0

From Datenwolf in this answer on stackoverflow: We can render tiles with a 2-loop: for m in 0 to M: for n in 0 to N: render_tile(n, m) where render_tile(n, m) starts by setting the viewport to the surface size (render target): glViewport(0, 0, W_t, H_t), for tile width and height W_t, H_t Somehow we've to shift the projection along with ...


1

OpenGL performance will outperform Swing quite heavily once you start doing something a little more advanced. I dont have hard numbers to back my claim, but I have experience. I too started out with pure Java2D, with BufferStrategy and the works. And it was ok for Pong, Snake, Tetris, and so on. But once venturing beyond in graphical effects (blending, ...


0

To calculate the arc of each block, do this: float arcDegrees = 360 / number_of_blocks_in_a_cylinder; In your image, for example, each "ring" of blocks is constructed of 12 blocks (the nearest three blocks aren't drawn in the image, but for the purposes of spacing, we pretend they're there) This means that each block covers an arc of 360 / 12 == 30 ...


59

OpenGL has four different major versions, not counting the versions for mobile devices and embedded systems (OpenGL|ES) and the Web via JavaScript (WebGL). Just like Direct3D 11 has a different way of doing things than Direct3D 8, so does OpenGL 3 have a different way of doing things than OpenGL 1. The big difference is that OpenGL versions are mostly just ...


1

Im not entirely sure about this myself, but maybe your problem is that you dont have one. From the looks of it, your skybox is rotating correctly. Question now: I see you are initializing and uploading the view-matrix correctly, but what about the projection-matrix, i dont see that one. My guess is that your code is alright so far, but since you havent ...


8

The primary difference is how up-to-date the strategies are. The immediate mode used in the first tutorial: glBegin(GL_QUADS); glColor3f(1, 0, 0); glVertex3f(0, 0, 0); glColor3f(1, 1, 0); glVertex3f(100, 0, 0); glColor3f(1, 0, 1); glVertex3f(100, 100, 0); glColor3f(1, 1, 1); glVertex3f(0, 100, 0); glEnd(); Is outdated and not supported on ...


0

Merge materials to use a single material per object as much as possible. Even sharing materials between objects if possible (eg: 1 leaf material, 1 ground material). You should batch up materials & VBOs to avoid state changes between opaque render calls. And you should not need to update most VBOs on every frames, the goal of VBOs is to leave the data ...


0

All you have to to is set glViewport then invert its transformation. Create a matrix s= tilecount; for(int x=0; x!=tilecount; x++) for(int y=0; y!=tilecount; y++) [s 0 0 x] [0 s 0 y] [0 0 1 0] [0 0 0 1] And multiply it * your modelviewprojection


0

My guess is your spot is pointing the wrong way. Try changing its direction to: GLfloat light0SpotDirection[] = {0.0,0.0,1.0}; glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light0SpotDirection); ( positive 1 for Z ) If I remember correctly the OpenGL light's direction must be set the opposite (negative) of the actual light direction as OpenGL does ...


3

Yes. FBO, shader (changing the currently active program, not necessarily shader state itself) and texture state changes tend to be the most expensive. Conversely, vertex pointers and uniforms tend to be the cheapest states to change. It is almost impossible to actually calculate the expense of any one state change in modern GL implementations; you might pay ...


1

You should not do that manually. Get a 3D modelling app (there are plenty free apps available) and make the model there, then import it in your program and use it there. If you need to hide parts of the model (alike the 90 degree section on you picture) then mark the blocks with e.g. different surfaces (tags) and choose to render or to skip them from ...


0

The sponza model from crytek loads bump map from an .mtl file where I found the "bump" map for the flooring.. map_bump textures\spnza_bricks_a_diff.tga bump textures\spnza_bricks_a_diff.tga If you take a look at these textures, they are clearly not normal / bump maps, and as the image name suggests; they are diffuse textures. If you swap the two names ...


1

Usage of glVertexAttribPointer is suspicious. glVertexAttribPointer( 2, // 3, // Mistake in TexCoords, should be 2 GL_FLOAT, // GL_FALSE, // 0, // Should be size of your vertex (void*)0 // Should be offset within vertex ); Check the documentation ...


0

You don't have to do it that way. That just happens to be one of the easier solutions that also give good results. You can also attempt to compile a font down to outlines and render those, but that's a lot harder. Note that what you're saying isn't that difficult because you can do it mostly automatically. And yes, there are libraries that already implement ...


2

Instead of building the cube in geometry shader from a point, its better to do an instanced render of a simple cube VBO, and forego a geometry shader entirely. The only time you wouldn't want to do that is if each cube has rapidly changing orientation and you need to recalculate its modelview every pass. In which case, have position and orientation as ...


0

From what I understand you are trying to render a scene many times from many views into a tilemap. To do that I would make each tile a layer of a Texture_2D_Array, and bind to a 3D framebuffer. In the first phase, render your scene instanced with view per instance, then in geometry shader (only place you can set it) set gl_Layer = instance. In the second ...


1

The new function is SDL_GL_SwapWindow() and it takes your window pointer.


2

The real question is what are you goals for this project? If you have a specific game in mind and just want to 'make it happen', then using something like Unity or Unreal is the sane approach. Creating an entire engine for anything but the simplest games is a huge endeavor. If, on the other hand, you are trying to gain skills and/or create a demo to land a ...


2

The different options out there are essentially as follows: Engine. An engine provides you with a high-level API through scripting and gives you many visual and non-visual tools to work with it. With an engine, you probably don't touch it's code, and the only thing you provide are resources which the engine loads at start of execution and that's it. ...


0

You're doing something strange: Every frame, you calculate the x,y,z values of the bullet's movement, based on a yaw and pitch that will never change. Why not create a vector3 that stores the direction and speed of the bullet in the bullet constructor? This way, you can do the calculations once per bullet, and then just add its speed vector to its current ...


4

By default, OpenGL assumes that your textures will have mipmaps attached. If you haven't attached any mipmaps to a texture, then OpenGL assumes that you didn't finish setting it up. OpenGL will therefore deem the texture to be "incomplete" and will refuse to render from it. In order to make your texture "complete" in OpenGL's eyes (and therefore usable ...


0

Well for one, your x,y,and z would stay zero based on moveFromPosition. If you want the bullet to follow a certain path, you need to get rid of the zeros, math calculates anything multiplied by 0 is equal to 0 Your next problem is you are over-complicating the math in moveFromPosition. All you need to do during an update is loc.x += ...


1

If you upload VBOs with many identical cubes inside of them you will just waste bus bandwidth. The keyword you should search for is "instanced rendering". There are many questions about it on here.


1

I think you mis-designed your API. Why does a window take an app, instead of an app taking multiple windows? An application can have multiple windows, but a window can only belong to one application. If you change this around there will be no need for multiple run loops. There will just be one in the application, and the application will handle events and ...


4

There are two obstacles you need to deal with in order to achieve similar quality like the one in the image, the first is artistic and the second is technical (memory, processing). First I assume that you already solved your artistic problem, you can make the models, the art and the shaders etc. (Partially because I can't answer art problems) The major ...


12

This is achieved by interpolating ramps between cubes of different height. When you have a scenery like this (seen from the side) # #### ## ############ you would add polygons to make it look like this: /#\ /####\ /##\ ############ An algorithm to calculate these ramps is the marching cubes algorithm. When you want it to be even more beautiful, ...


1

One distance field cannot represent sharp corners, because within the space between 4 samples (i.e. inside each "square pixel", even though pixels are not little squares), the value of the distance field is a quadratic function due to bi-linear interpolation. This class of quadratics cannot represent sharp corners well, because they are polynomials and ...


1

In short: no. S3TC and other compression formats will destroy your 16bit values. Texture compression formats have a fixed compressed size and therefore need to be lossy in order to ensure this. If you need 16bits of lossless data you must use a non-compressed format. Ideally GL_R16UI.


3

Your geometry shader should take a single point (center of the cube) with a front vector and an up vector. You can then output 12 triangles (6 faces x 2 tri for a quad) using the single point as the center of the cube and the cross-product of front & up for the right vector. // table of all triangle vertices to make the cube const vec3 face_table[12*3] ...


5

Sarting with the clouds, a simple method is to draw them as three layers: Layer 1 is the bottom layer, and is drawn first. It just contains the cyan background. Layer 2 is the middle layer, drawn between the other two, and it represents the 3D highlights. The background in this layer would again be transparent (represented by a purple colour in the ...


4

Spherical harmonics lighting use spherical harmonics to approximate a lighting lobe on an object. It has property that make it cheap to compute in real time (dot product vs the normal) and to store (7floats per channels generally, for example in unity engine, but it vary based on the use, The movie avatar used spherical harmonics with 81floats per ...


1

Spherical harmonics is a general mathematical concept that can be applied to a number of problems. One of those problems is modeling the behavior of light for use in 3D rendering. There's not really a difference, just a scoping of the application. It's sort of like asking "What's the difference between Fourier Analysis and Fourier Analysis of Sound ...


3

You could achieve this effect using parallax scrolling by making the earth and each shade of green a separate layer. With a parallax effect, no 3D calculations are required, and you get to stay with the pixelated, simple color style you're using. Note that parallax doesn't have to be limited to just horizontal motion. Vertical movement (when the camera ...


-2

TL;DR it's not 4D space, it's 3D plus a scaling number which is virtually always 1. If it is 1, you can ignore it and the first three numbers are x,y,z. If not it gets more complicated. Here's a simple explanation. Vertices in 3D should only have three components [x v = y z] If we want to manipulate them (e.g. rotation, scaling etc.) we use a ...


0

After a full day of testing and google searching I finally came upon the fix so I'm sharing it here : uniform vec2 Resolution;//This is the render target size, i.e. what you feed into glViewport vec2 screen; screen.x = ( gl_FragCoord.x - Resolution.x / 2.0 ) / ( Resolution.x / 2.0 ); screen.y = ( (Resolution.y - gl_FragCoord.y) - ...


0

You can add a depth component to your 2D textures and set the depth value in the pixel shader. There will be some performance loss due to setting the depth in the pixel shader but shouldn't matter for a 2D game on PC. The other way is to use multiple layers of 2D textures for your background.


1

I think it's the line right above it: vec3 shadowAmount = 1; change it to: vec3 shadowAmount = vec3(1.0); Looks like your line numbering is off by one. Otherwise try explicitly casting to int in case the compiler has a different bug. int shadowMap = (int)(lightToShadowMapMapping[i]);


1

If you use a point sampler for your mask texture, then you can store as many IDs as bits in your texture: for a 32-bit RGBA texture you'd be able to store 128 different IDs. In such a case though, as you have a single bit per ID, there's virtually no blending as you have only 0 or 1. The more bits you devote per ID, the greater the blending granularity, ...


0

For me the fastest way has been "Find in files" feature of the IDE / text editor. Recursively searching for the function name from either LWJGL API documentation or source folder quickly reveals the correct class name. This is just a few key presses compared to switching to a web browser and searching from the reference pages.


0

The reference material on the OpenGL website is a good source for this. The function reference pages there have a "Version Support" section that details which version of the API the function in question is available in. Here's the page for glDrawElementsBaseVertex, for example. A machine-readable form of this data is available via the API XML, which would ...


0

Double check if you are truly using viewport correctly. You're not rebinding the texture to the FBO. That SHOULDN'T be necessary, however the spec makes no guarantee that glTexImage won't screw up any attached framebuffers, so assume that it can. If that doesn't work then its the way you're sampling from it. For simply allocating a texture with undefined ...


1

It is pretty complicated stuff going on and its not that simple as it look bcs of the way of opengl buffering system works.The best way to do it is just draw 3d and then 2d. You might create some kind of ArrayList which will keep track of all 2d drawing requests. And when 3d is done you execute them all.


1

It is technically possible with OpenGL ES 2 but almost no device currently support it. You'll have to check GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS on devices. For small "textures" you can use a small array of uniforms. A lot of (old) desktop video cards still in use only supports GL_LUMINANCE32F_ARB and GL_RGBA32F_ARB or don't support any VTF at all. If you ...


2

To be safe I'd delete and recreate the entire FBO. Some drivers have strange stability issues when recycling/resizing FBOs. I've had entire screen flickers and occasional crashes. Switching attached textures to another of the same size & type seem to work fine all the time on all drivers but with some drivers it is much faster (more than 100x) to have ...


1

According to OpenGL Insights there are a couple ways to efficiently stream data to a VBO. A simple but efficient method is to "orphan" the buffer (allocating a new piece of VRAM in the process) and refill the entire thing. This allows the current frame to use the old data while you can upload the new data. // orphan the buffer so that we can write new ...


1

Pros Higher resolution should give the player more visual information about the game world. Everything will be clearer and more sharply defined. This should confer an advantage in overall situational awareness, which in an FPS is important. There should be no effect on game state as the game engine does not compute the position of objects and actors based ...



Top 50 recent answers are included