Archived

This topic is now archived and is closed to further replies.

MARS_999

OpenGL Is it possible to do a top down RTS in OpenGL?

Recommended Posts

MARS_999    1627
Is it possible to do a top down view like TA in OpenGL? I think it is but not sure how one would go about it? Would I use glOrtho() or gluPerspective()? I am not sure, but from what I see TA''s tilesets are 2D textures? So if that is the case then the only 3D part of the game is the units. Which you would have to use 3DS for right? Now if you use those units you will have to use gluPerspective() so you have all three axis''s. Because if you use glOrtho() and you have an airplane fly by and do a roll its not going to show up when its rolling. So if I use a tile based engine with 512x512 textures for the map, wouldn''t I need to load each 512x512 texture with a heightmap and somehow determine the height at any given textel on the screen? Any help would be great thanks!! Bill Gates is my Pool Boy!! Nothing is to good for me!!

Share this post


Link to post
Share on other sites
invective    118
newer 3d rts games use 3D maps with variable hieght terran (empire earth, warcraft 3). Just do the whole thing in 3D. Storing a hieghtfield is cheap anyways (just 8 bits more per tile, plus they compress well). Use a perspective projection and keep the camera at some fixed distance from the ground plane looking down at a fixed angle (most games let you scroll down to horizontal with the mouse wheel, but for gameplay, thats worthless). If you have seen war3, they basically still use tiles for textures instead of the more tranditional large texture / detail texture used in most terrain renderers.

Share this post


Link to post
Share on other sites
MARS_999    1627
How about using a Iso Metric view in OpenGL? Where could I find info on that? I looked around on the gamedev and looks like all tutorials are on DirectX? I would prefer to do the game as a Iso Metric view since I like the way those kind of games play. Thanks!

Bill Gates is my Pool Boy!!
Nothing is to good for me!!

Share this post


Link to post
Share on other sites
zedzeek    528
>>How about using a Iso Metric view in OpenGL? Where could I find info on that? I looked around on the gamedev and looks like all tutorials are on DirectX? I would prefer to do the game as a Iso Metric view since I like the way those kind of games play. Thanks! <<

yes its possible look atsetting up a orthogonal viewport +
setup the camera like so

gluLookAt(-10,sqrt(200),10,0,0,0,0,1,0) as an example

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
MARS_999    1627
quote:
Original post by zedzeek
>>How about using a Iso Metric view in OpenGL? Where could I find info on that? I looked around on the gamedev and looks like all tutorials are on DirectX? I would prefer to do the game as a Iso Metric view since I like the way those kind of games play. Thanks! <<

yes its possible look atsetting up a orthogonal viewport +
setup the camera like so

gluLookAt(-10,sqrt(200),10,0,0,0,0,1,0) as an example

http://uk.geocities.com/sloppyturds/gotterdammerung.html


Ok here is what I got setup and am seeing nothing? My code compiles fine but not sure why I don''t see a simple quad?


  
void Draw(void)
{
glLoadIdentity();
gluLookAt(-10, sqrt(200), 10, 0, 0, 0, 0, 1, 0);

glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-10.0f, -10.0f);
glVertex2f(10.0f, -10.0f);
glVertex2f(10.0f, 10.0f);
glVertex2f(-10.0f, 10.0f);
glEnd();
}

bool InitOpenGL(int width, int height)
{
float ratio = float(width) / float(height);

glViewport(0, 0, width, height);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);

glDepthFunc(GL_LEQUAL);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(0.0f, float(width), 0.0f, float(height), -1.0f, 100.0f);

glMatrixMode(GL_MODELVIEW);

return true;
}


I think I got everyting setup right? Thanks for the help in advance. =)

Bill Gates is my Pool Boy!!
Nothing is to good for me!!

Share this post


Link to post
Share on other sites
zedzeek    528
your screen is say 1024x768 pixels large, though that quad is only 20x20 pixels large thus it might be a bit small

use 3d vertices (x,y,z) y is going up
eg

glVertex3f(-10.0f, 0, -10.0f);
glVertex3f(10.0f,0, -10.0f);
glVertex3f(10.0f, 0, 10.0f);
glVertex3f(-10.0f, 0, 10.0f);

turn off backface culling, texturing/alphatest/lighting etc

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
MARS_999    1627
quote:
Original post by zedzeek
your screen is say 1024x768 pixels large, though that quad is only 20x20 pixels large thus it might be a bit small

use 3d vertices (x,y,z) y is going up
eg

glVertex3f(-10.0f, 0, -10.0f);
glVertex3f(10.0f,0, -10.0f);
glVertex3f(10.0f, 0, 10.0f);
glVertex3f(-10.0f, 0, 10.0f);

turn off backface culling, texturing/alphatest/lighting etc

http://uk.geocities.com/sloppyturds/gotterdammerung.html


Great its showing up now. I am a little consfused on how I should move the screen around now? I must have to make a bi-axis move now to move on what would have been one axis before? The image is showing up on the far left and would like to move it to the center of the screen so I can get a better look at it. The quad don''t look right but like I said I can''t see the whole quad. I have to admit I have only worked with glOrtho() as a x,y axis map and glPerspective as x,y,z using glTranslatef() and glRotatef() so this is all new to me. =) Thanks

Bill Gates is my Pool Boy!!
Nothing is to good for me!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
if it''s just 2d you can use glOrtho2d and 2d coordinates

Share this post


Link to post
Share on other sites
Heaven    600
There is nothing prohibiting you from using ortho to make a top-down RTS, even one with 3D units. Ortho just means that there is no perspective correction, where things get smaller with distance or lean a certain way near the edges of the screen.

Check the screenshots at my website (below) for an example of me starting out with ortho and switching to perspective. While I''m not using 3D units, you can still see the difference.

Speaking of TA, I believe it used 3D terrain AND 3D units, same as TA:K. The terrain utilized height-mapped sections with 2D textures mapped onto them.

And where do you get the idea that you can''t see a rolling plane in ortho projection? Ortho is just a method of projecting things onto the screen. There is no perspective in ortho, so there is no reduction/enlargement based on distance. I.e., that plane right at your nose and 50 units into the screen will still look the same size unless you scale it or your viewport.


Care,
Chris Rasmus

Florida, USA
RTS Engine in Development
http://www.knology.net/~heaven
Jesus is LORD!

Share this post


Link to post
Share on other sites
MARS_999    1627
quote:
Original post by Heaven
There is nothing prohibiting you from using ortho to make a top-down RTS, even one with 3D units. Ortho just means that there is no perspective correction, where things get smaller with distance or lean a certain way near the edges of the screen.

Check the screenshots at my website (below) for an example of me starting out with ortho and switching to perspective. While I''m not using 3D units, you can still see the difference.

Speaking of TA, I believe it used 3D terrain AND 3D units, same as TA:K. The terrain utilized height-mapped sections with 2D textures mapped onto them.

And where do you get the idea that you can''t see a rolling plane in ortho projection? Ortho is just a method of projecting things onto the screen. There is no perspective in ortho, so there is no reduction/enlargement based on distance. I.e., that plane right at your nose and 50 units into the screen will still look the same size unless you scale it or your viewport.


Care,
Chris Rasmus

Florida, USA
RTS Engine in Development
http://www.knology.net/~heaven
Jesus is LORD!


Wow it works!! glOrtho() will do 3D. =) Oops my bad. Now I can do a game in glOrtho() top down and use 3D units. I am not worried about perspective since I can enlarge or shrink my units to make them look in proportion. Thanks a million. Now off to work on code to load .3ds models.

Bill Gates is my Pool Boy!!
Nothing is to good for me!!

Share this post


Link to post
Share on other sites

  • Similar Content

    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

    • By altay
      Hi folks,
      Imagine we have 8 different light sources in our scene and want dynamic shadow map for each of them. The question is how do we generate shadow maps? Do we render the scene for each to get the depth data? If so, how about performance? Do we deal with the performance issues just by applying general methods (e.g. frustum culling)?
      Thanks,
       
  • Popular Now