Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Learn OpenGL

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
Learn OpenGL
Elias
Member #358
May 2000

Btw. Allegro comes with an example that displays a skybox: https://github.com/liballeg/allegro5/blob/master/examples/ex_camera.c

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Neil Roy said:

Here, you may need this.

I always knew you rolled your toilet paper upside down. Blasphemy!

Elias said:

an example that displays a skybox

{"name":"611229","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/e\/9e5bed09f24e3dc30de79ffc7a979c06.png","w":642,"h":401,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/e\/9e5bed09f24e3dc30de79ffc7a979c06"}611229
Nice corner. :/

Still working on my example. Will report back.

bamccaig
Member #7,536
July 2006
avatar

Neil Roy
Member #2,229
April 2002
avatar

I always knew you rolled your toilet paper upside down. Blasphemy!

Actually, mine is hung properly, only not on a normal roll, but I have a hanger I bent so that I can hang in from a towel rack and not have to become a contortionist to use it! 8-)

{"name":"611230","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/8\/888f58fb9b21db36c295f6fa228cc9ff.jpg","w":512,"h":695,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/8\/888f58fb9b21db36c295f6fa228cc9ff"}611230

---
“I love you too.” - last words of Wanda Roy

Ariesnl
Member #2,902
November 2002
avatar

Some things are the same in every part of the world. ;D
I wonder what they use in the amazon forrest

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Chris Katko
Member #1,881
January 2002
avatar

I imagine they use something involving The Cloud.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Neil Roy
Member #2,229
April 2002
avatar

Ariesnl said:

I wonder what they use in the amazon forrest

Probably small furry creatures. ;D

---
“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

My skybox is seriously messed up.

EDIT
{"name":"611235","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/170e1bca67919e58d6529e9187c92fa2.png","w":802,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/170e1bca67919e58d6529e9187c92fa2"}611235
{"name":"611236","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/c\/dc131e5187f62ae06b579cf24812e71a.png","w":802,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/c\/dc131e5187f62ae06b579cf24812e71a"}611236

Chris Katko
Member #1,881
January 2002
avatar

It's a feature!

You're just holding the monitor wrong.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I tried to do it with just one texture but my tex coords must be off. I'm also drawing the cube with two triangle fans, because two opposing vertices touch all the other faces. Gonna take a look at your City3D program a little later for some hints. I still don't think it's going to look right.

Neil Roy
Member #2,229
April 2002
avatar

Looks like you're using an orthographic view instead of a perspective one.

Here's the complete source code with Code::Blocks project for my City3D. It's a project I have been messing around with since 2004. It includes a separate Allegro 4 project for the map editor (already compiled), it's just a 2D editor that saves to the same map name each time. If you're curious about other maps, just rename them to city.map and the program will load them.

The main program doesn't use Allegro, it doesn't use anything (except the freeimage library, though I have separate code to load uncompressed TGAs which can be used instead). This is a Windows (IE: WinMain()) project, no allegro, no sdl2, nothing. It was something I started in order to learn a little straight Windows coding. The OpenGL stuff is pretty straight forward, if you can handle my coding style and C only code.

Oh, and I changed my code to use all QUADS, no triangles, though they could be used, I tried to keep it as simple as possible to make learning OpenGL easier, which is why I also stuck to a grid layout and cubes at the time (before Minecraft! heh).

I added in keys (listed on the main screen when you run it) to show wireframe mode, so you can see what is drawn. TO enable/disable Vsync, to enable/disable fullscreen mode, disable the onscreen text (except the FPS) which can speed things up a tad. SHIFT key goes super fast, use E and Q to fly up in the air (better when zipping around the map). Frustum culling can be toggled, note, my frustum culling is simple, and only culls to the right and left, but doesn't take into account your angle looking up and down (because this was meant to be only driving, no flying and looking up and down). You can toggle the skybox on and off as well etc... the code may help. Maybe try converting this to use Allegro as the main framework? I plan to convert this to modern opengl, should be interesting to see the FPS difference.

https://www.dropbox.com/s/r4bea14ll60vcz9/City3D_source.7z?dl=0

---
“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

bamccaig
Member #7,536
July 2006
avatar

Hah, I stayed up all night too. I feel like shit today though. :(

Append:

I guess this wasn't the O/T thread... Whoops.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I don't know what I'm doing wrong. My cube coordinates look right, and so do my texture coordinates.

{"name":"611241","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d6d68a2224a1ecd4d3cb22580ea3a32b.png","w":1365,"h":847,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d6d68a2224a1ecd4d3cb22580ea3a32b"}611241

Elias
Member #358
May 2000

I think it would be nice adding an actual texture to the ex_camera skybox - maybe I'll do that tonight. The skybox code in there originally is from a textured version so I can just copy&paste it back in and I'll add a command-line paramater to specify a picture with the skybox.

Otherwise, from your screenshot it definitely looks like some of the UV coordinates are off. Also - are you sure your camera is inside of your box? It won't work if you look at it from the outside.

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

That screenshot is with an orthographic projection, so I can see the cube, because for some reason it doesn't show up when I use a perspective projection. I'll put my code up on GitHub. https://github.com/EdgarReynaldo/Skybox

EDIT
I enabled GL_CULL_FACE, I set the front face to GL_CCW, and I set it to cull backfaces, but I see the outside of my skybox. What gives? I know I wound the vertices in CCW order.

EDIT2
My skybox and my cube are both inside out, but I don't know why.

EDIT3
I think it has something to do with the handedness of OpenGL. My vertices are wound perfectly counterclockwise, but when I print them out, they are wound in clockwise order? WTF?

Neil Roy
Member #2,229
April 2002
avatar

You're using Orthographic projection. That is not 3D and will never work.

---
“I love you too.” - last words of Wanda Roy

Elias
Member #358
May 2000

Here is an updated ex_camera: https://github.com/liballeg/allegro5/compare/master...allefant:skybox

I called it like this: ./ex_camera /tmp/skybox.png

And it looks like this:

There is some white border around the top face but I think that's because of Neil's source picture, adding a few pixels where he has white there likely would fix it!

{"name":"611244","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/496cc9b40906b13bfa6cceed84e840f8.png","w":1140,"h":739,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/496cc9b40906b13bfa6cceed84e840f8"}611244

--
"Either help out or stop whining" - Evert

Neil Roy
Member #2,229
April 2002
avatar

I never did test that image. Is it edge clamped? I attached the original separate images in a 7z to this message if you want to work with them, to redo that.

---
“I love you too.” - last words of Wanda Roy

Elias
Member #358
May 2000

Ha, no, I just used the picture you posted and set the U/V coordinates to 0.25/0.33 - so they simply include the white pixels. Only hacked it in in half an hour or so. Just wanted to confirm that indeed all you do is paste a texture on the inside of an unlit untranslated cube - and ex_camera already was doing everything (except apply a texture).

--
"Either help out or stop whining" - Evert

Neil Roy
Member #2,229
April 2002
avatar

Ah, okay. Yeah, it is much simpler than some realize. A sort of optical illusion. The concept is simple enough. If you want a 360 degree view all around you, and you have four sides all the same size, than you make each view 360/4 degrees, or a 90 degree field of view.

Terragen is handy for that, it's what I used. It doesn't have degrees (the old version anyhow), but the ZOOM factor when set to 1 even, equals 90 degree field of view. After that, just render each direction to a 512x512 texture and you're all set.

Anyhow, the original pics are in that zip if anyone wants them separate. I only done it in that single cross shape because that is the most common I find online.

---
“I love you too.” - last words of Wanda Roy

 1   2   3 


Go to: