nandor / hcraft

Haskell clone of a certain game
MIT License
95 stars 6 forks source link

Unable to create OpenGL context #2

Open MasseGuillaume opened 10 years ago

MasseGuillaume commented 10 years ago

after

> cabal install
> dist/build/hcraft/hcraft

Unable to create OpenGL context Cannot create window

nandor commented 10 years ago

You need OpenGL 4.1 to run the game.

osa1 commented 10 years ago

@MasseGuillaume I ported the game to OpenGL 3.1 https://github.com/osa1/hcraft

Graphics looks a bit buggy though. I'm not sure if the original version is also like this. @nandor could you try and tell me if something's wrong in my port?

nandor commented 10 years ago

Do you have an ATI card? There's a chance I'm doing something stupid that NVIDIA drivers don't care about, but the OpenGL spec forbids it.

osa1 commented 10 years ago

No, I'm trying on onboard Intel.

What I'm seeing may not be a buggy rendering, I'm just saying it doesn't look great but I'm not sure if this is because I messed with stuff while working on porting to OpenGL 3.1.

nandor commented 10 years ago

I've used cube map arrays & 3D textures, maybe those are not supported on Intel GPUs.

osa1 commented 10 years ago

I'll post a screenshot tonight.

nandor commented 10 years ago

I've just tested it on my computer, it works fine, although in my opinion it's not correct. In order to port it, you should change the algorithm.

I have used OpenGL 4.0+ features in order to minimize the amount of data transferred between the CPU and the GPU. I have a large global mesh containing all the vertex, normal and UV data (3Mb) and a cube map array containing the textures for the cubes. Individual chunks only have an index array and small 16x16x16 texture which contains the IDs of the blocks. When I render a face, I look up the ID of the cube in the 3D texture and select the corresponding cube map from the array. I'm not sure how efficient this algorithm is. In terms of bandwidth, I think it's okay (when a chunk is modified, only a new IBO and a 3D texture have to be uploaded).

To correctly port the game to OpenGL 3.1, you'd have to remove everything related to cube map arrays (they were introduced in OpenGL 4.0).

osa1 commented 10 years ago

I also compared my port with original version on a computer that supports GL 4 and results looked pretty similar. I think I'm doing what you describe using an extension https://github.com/osa1/hcraft/commit/0d081c846cd53133c9dde2262583c975ed619209#diff-f96787e0aa93b3ae45a62013d85097f1R5 so it's not necessary to rewrite the whole rendering algorithm.