• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KaiserJohan

OpenGL
Jumping over to DirectX?

17 posts in this topic

I've done some progress on learning OpenGL (models, textures, lights, point light/directional cascaded shadow maps, deferred rendering with msaa) and I'm pondering whether to make the jump over to DirectX.

 

pros:

  1. API design. As my rendering pipeline gets more complex, structuring all the various state calls into something easily understandable yet fast gets increasingly annoying, especially under some form of OOP. Is this the case for DirectX aswell? Is there a big difference?
  2. Debugging tools. AFAIK, Visual studio has built in performance and debugging tools for directx, while doing the same for opengl has proven so far to be a nightmare. There is gDEbugger (and CodeXL) but they simply don't work/crash, probably something with the window framework I'm using (GLFW 3) and it's OpenGL context switches. I work in windows under Visual studio anyway, so tight integration with debugging tools seems too good to be true.

cons:

  1. Supporting frameworks. I'm using GLEW for loading OpenGL, GLFW 3 for window management and GLM for math stuff. I have to say they are some of the best libraries I have used; my main issue with jumping to DirectX would be that I would have to get equivalent frameworks for that, and some searching has yielded basically NOTHING.
  2. Tutorials/references. The majority of what I have found seems to be OpenGL focused - DirectX guides seems kinda lackluster. Is this true?

Anyone mind chiming in with some feedback?

 

0

Share this post


Link to post
Share on other sites

You will get both side of the coin on this one..ultimately you will have to make the decision based on your experience with both. Without taking the plunge, you will never get a comprehensive unbiased evaluation of the two. I started out with DX 8.1 and continue throughout the years and the API has come a long way. DX used to be more forward thinking in terms of functionality, but there is parity between the 2 nowadays ( my opinion ). Currently, I'm leaning more to OpenGL because of its broad adoption across multiple devices and hardware configuration. The biggest gripe I have with DX now is the bonding of DX with OS ( need MS latest OS to use the latest DX features ). In the end they are both API to access the graphics HW for rendering/compute purposes.

For you pros and cons

Pro

1. DX is more structured that OpenGL and kudos to MS for giving that some thought. There are still different pipeline states to worry about, but again, the handling is much cleaner in DX.

2. Again, DX has the leg up on OpenGL for this one. I was a big fan of PIX ( RIP ), but there are plenty of tools out there for debugging D3D apps. The 2 that you mentioned on the OpenGL front are very good tools. I use CodeXL on a daily basis and the latest version is more stable. I also run AMD HW so I cannot comment on the stability on other HW, but it has been an invaluable tool to me. I've found 1 issue that causes it to crash/hang so avoid doing that, and so far so good.

Con:

1. As DX doesn't have an extension mechanism like OpenGL, there is not need for GLEW with DX. GLUT is a windowing utility toolkit thats tied to OpenGL so either you roll your own or use one of the may equivalent out there ex SDL. As GLM, there is nothing OpenGL inherent in math, the difference usually boils down to coordinate system convention, matrix storage layout etc..

2. The SDK documentation and samples ( installed with the SDK ) are very good and should be all you need to get your feet wet in DX.

-1

Share this post


Link to post
Share on other sites

#L.Spiro:

 

1. I would more likely say "welcome to light side". For me, the only strong argument why I'm using OpenGL in most of my applications is one - Linux (this counts especially when you're not developing games, but software for doing various high performance computations).

 

2. Comparing bare bones applications will show you larger difference in speed, than for case of F.e. full game. But generally yes, D3D will perform better.

 

#OP & thread generally:

 

I won't even mention debugging - under OpenGL we literally had to develop our own tools from scratch (they work well, but it took us hell a lot of time to create them).

 

Dealing with AMD vs NVidia vs any other vendor (and often driver versions) under OpenGL, with some recent features, is a bloody mess (I still remember moment, where one user of my applications had troubles with 3D textures and Intel gpu, that officially supported 3D textures extension (and also OpenGL version, where it was promoted into core), but once you sampled 3D texture inside shader, you were doomed.

 

So, as for me - go right away, switch to D3D.

Edited by Vilem Otte
0

Share this post


Link to post
Share on other sites

Small addition on tutorials/ learning DX11. You could buy the book '3D Game programming with DirectX11' by Frank D Luna), good learning curve and readability.

0

Share this post


Link to post
Share on other sites

I'll just add that how easy D3D is going to be for you will depend very much on how you're currently using OpenGL.  If you're used to modern OpenGL then you shouldn't have much problem translating the concepts over, but if you're still in glBegin/glEnd land you're likely to have an awful time.

 

If the latter is the case it may serve you better to do some research programs using modern OpenGL first, just to help you get a good understanding of the differences you're going to have to deal with when you port your main codebase (and to have that learning experience in a more familiar environment).

0

Share this post


Link to post
Share on other sites


You could buy the book '3D Game programming with DirectX11' by Frank D Luna

That's a great book; far better than any online tutorial I've seen.

With one exception: Luna uses D3DX. kunos already mentioned the DirectX toolkit libraries; these should be used instead in new code.

0

Share this post


Link to post
Share on other sites
Two remarks as an addition:
- PIX works fine with dx11 applications (if 32bit)
- the book uses both DirectxMath as D3DX, I think this shouldn't you from learning a lot from the book in a good readable way with doable learning curve (you can adapt other libraries when you encounter d3dx stuff while your going through the book)
0

Share this post


Link to post
Share on other sites

Please stay away from Direct3D!!

 

I can't speak for the API design or any of that, but Direct3D is only available for one platform. (As I understand it, the XBox version is actually a different API). If you learn Direct3D, and later decide that you want to target Linux, OS X, Android, iOS, PlayStation, et cetera, then you'll need to go back to OpenGL.

 

Right now, I guess you're only concerned about Windows. But think about 5, 10 years from now. Windows is the most popular OS because people are used to it, and developers don't bother to target other platforms. That's changing. College students are picking up OS X and finding it to be a smoother experience. Nerdy, curious developers like myself are installing Linux on an old computer or in a virtual machine, and finding out how much freedom it provides (you don't need to alter any source code, just change settings). Windows is on the decline.

 

Plus, there's the whole mobile device thing. You want into that market, and you need to know OpenGL ES.

 

If you really think that Direct3D offers enough benefits to warrant learning it, go ahead. But first, do yourself a favor: try Linux. Install it in a virtual machine, or an old computer, or set up a dual-boot on your current computer. Experiment a little. Try to find the right desktop environment for yourself. If it turns out you like GNOME, or KDE, or Unity, or one of the other thousands of desktop environments (just try five or so, not all of them) better than what you get with Windows, then it's better you find that out before you devote a bunch of time to learning an API that won't work on other platforms.

 

I used to use Windows, and I couldn't understand why anyone would bother to use anything else. But once I tried Linux, I realized that I'll never again be satisfied with an OS that forces me to pay for every new version, requires anti-virus, hogs my system resources, and won't let me customize things.

 

All I'm asking is that before you jump to a proprietary, single-platform, can't-get-the-latest-features-without-buying-a-new-OS-that-you-may-hate API, you make sure you're okay with only ever releasing games for that platform.

 

Sorry for the rant about the awesomeness of Linux. I just think that--especially with SteamOS--you need to take it into account.

-5

Share this post


Link to post
Share on other sites

Well, sorry for offering my opinion and advice. I can see I'm not welcome here. Please continue misinterpreting my post and upvoting everyone who acts like a jerk towards me. Seriously. Knock yourself out. I'm used to being treated like crap for having a different opinion.

-6

Share this post


Link to post
Share on other sites


4) OS X is stuck in the low 4.1 OpenGL support so no modern features for you

 

My GPU (GTS 250), old as it is, can still run 95% of the triple-A games on PC, and it only supports up to OpenGL 3.3.  If you're targeting above 4.1 for "modern features", things like platform choice no longer matter because you don't really have a platform at that point unless you don't want to release for another 5 years.

0

Share this post


Link to post
Share on other sites
The prevailing direction is towards heavy compute based architectures which, yes, requires two rendering paths anyway ("legacy" and "compute") if you want to cover old hardware however in the AAA space at least pre-11 hardware is becoming less of a focus so your 95% will drop off pretty quickly now.

More to the point if you are working on something now then your release window is likely to be a couple of years away so saying "well, this is good enough now.." gets you no where. (A release window of less than that probably requires an existing engine, either in house or purchased, so the choice of renderer backend is already fixed either for the initial target or whatever the purchased engine supports).

Either way, Apple have shown no interest in updating OpenGL support on OSX and, despite the hardware being able to, do not support compute shaders (beyond other things) which is a major issue for many people.

Regardless pre-DX11 class hardware is yet another render path, regardless of platform or API.
1

Share this post


Link to post
Share on other sites

Well, sorry for offering my opinion and advice. I can see I'm not welcome here. Please continue misinterpreting my post and upvoting everyone who acts like a jerk towards me. Seriously. Knock yourself out. I'm used to being treated like crap for having a different opinion.

 

You wrote:

 

 

Right now, I guess you're only concerned about Windows

 

But yet the OP had already stated (in post #5) that Linux is currently a target platform.

 

You wrote:

 

 

If you learn Direct3D, and later decide that you want to target Linux, OS X, Android, iOS, PlayStation, et cetera, then you'll need to go back to OpenGL

 

And that's as scurillous as the infamous Wolfire blog post because most of those platforms don't actually use OpenGL (best of luck trying to port desktop GL code to GL ES).

 

Frankly, I could go on here but what's the point?  This isn't "opinion and advice", this is misinformation.  There's nothing wrong with giving opinion provided you've got facts to back it up, and in this case you don't - you are in fact just giving a sales-pitch for Linux to someone who was already targetting it anyway, and using false information to support that sales-pitch.

 

That's why you were downvoted.

Edited by mhagain
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By Solid_Spy
      Hello, I have been working on SH Irradiance map rendering, and I have been using a GLSL pixel shader to render SH irradiance to 2D irradiance maps for my static objects. I already have it working with 9 3D textures so far for the first 9 SH functions.
      In my GLSL shader, I have to send in 9 SH Coefficient 3D Texures that use RGBA8 as a pixel format. RGB being used for the coefficients for red, green, and blue, and the A for checking if the voxel is in use (for the 3D texture solidification shader to prevent bleeding).
      My problem is, I want to knock this number of textures down to something like 4 or 5. Getting even lower would be a godsend. This is because I eventually plan on adding more SH Coefficient 3D Textures for other parts of the game map (such as inside rooms, as opposed to the outside), to circumvent irradiance probe bleeding between rooms separated by walls. I don't want to reach the 32 texture limit too soon. Also, I figure that it would be a LOT faster.
      Is there a way I could, say, store 2 sets of SH Coefficients for 2 SH functions inside a texture with RGBA16 pixels? If so, how would I extract them from inside GLSL? Let me know if you have any suggestions ^^.
    • By DaniDesu
      #include "MyEngine.h" int main() { MyEngine myEngine; myEngine.run(); return 0; } MyEngine.h
      #pragma once #include "MyWindow.h" #include "MyShaders.h" #include "MyShapes.h" class MyEngine { private: GLFWwindow * myWindowHandle; MyWindow * myWindow; public: MyEngine(); ~MyEngine(); void run(); }; MyEngine.cpp
      #include "MyEngine.h" MyEngine::MyEngine() { MyWindow myWindow(800, 600, "My Game Engine"); this->myWindow = &myWindow; myWindow.createWindow(); this->myWindowHandle = myWindow.getWindowHandle(); // Load all OpenGL function pointers for use gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); } MyEngine::~MyEngine() { this->myWindow->destroyWindow(); } void MyEngine::run() { MyShaders myShaders("VertexShader.glsl", "FragmentShader.glsl"); MyShapes myShapes; GLuint vertexArrayObjectHandle; float coordinates[] = { 0.5f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, 0.5f, 0.0f }; vertexArrayObjectHandle = myShapes.drawTriangle(coordinates); while (!glfwWindowShouldClose(this->myWindowHandle)) { glClearColor(0.5f, 0.5f, 0.5f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw something glUseProgram(myShaders.getShaderProgram()); glBindVertexArray(vertexArrayObjectHandle); glDrawArrays(GL_TRIANGLES, 0, 3); glfwSwapBuffers(this->myWindowHandle); glfwPollEvents(); } } MyShaders.h
      #pragma once #include <glad\glad.h> #include <GLFW\glfw3.h> #include "MyFileHandler.h" class MyShaders { private: const char * vertexShaderFileName; const char * fragmentShaderFileName; const char * vertexShaderCode; const char * fragmentShaderCode; GLuint vertexShaderHandle; GLuint fragmentShaderHandle; GLuint shaderProgram; void compileShaders(); public: MyShaders(const char * vertexShaderFileName, const char * fragmentShaderFileName); ~MyShaders(); GLuint getShaderProgram(); const char * getVertexShaderCode(); const char * getFragmentShaderCode(); }; MyShaders.cpp
      #include "MyShaders.h" MyShaders::MyShaders(const char * vertexShaderFileName, const char * fragmentShaderFileName) { this->vertexShaderFileName = vertexShaderFileName; this->fragmentShaderFileName = fragmentShaderFileName; // Load shaders from files MyFileHandler myVertexShaderFileHandler(this->vertexShaderFileName); this->vertexShaderCode = myVertexShaderFileHandler.readFile(); MyFileHandler myFragmentShaderFileHandler(this->fragmentShaderFileName); this->fragmentShaderCode = myFragmentShaderFileHandler.readFile(); // Compile shaders this->compileShaders(); } MyShaders::~MyShaders() { } void MyShaders::compileShaders() { this->vertexShaderHandle = glCreateShader(GL_VERTEX_SHADER); this->fragmentShaderHandle = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(this->vertexShaderHandle, 1, &(this->vertexShaderCode), NULL); glShaderSource(this->fragmentShaderHandle, 1, &(this->fragmentShaderCode), NULL); glCompileShader(this->vertexShaderHandle); glCompileShader(this->fragmentShaderHandle); this->shaderProgram = glCreateProgram(); glAttachShader(this->shaderProgram, this->vertexShaderHandle); glAttachShader(this->shaderProgram, this->fragmentShaderHandle); glLinkProgram(this->shaderProgram); return; } GLuint MyShaders::getShaderProgram() { return this->shaderProgram; } const char * MyShaders::getVertexShaderCode() { return this->vertexShaderCode; } const char * MyShaders::getFragmentShaderCode() { return this->fragmentShaderCode; } MyWindow.h
      #pragma once #include <glad\glad.h> #include <GLFW\glfw3.h> class MyWindow { private: GLFWwindow * windowHandle; int windowWidth; int windowHeight; const char * windowTitle; public: MyWindow(int windowWidth, int windowHeight, const char * windowTitle); ~MyWindow(); GLFWwindow * getWindowHandle(); void createWindow(); void MyWindow::destroyWindow(); }; MyWindow.cpp
      #include "MyWindow.h" MyWindow::MyWindow(int windowWidth, int windowHeight, const char * windowTitle) { this->windowHandle = NULL; this->windowWidth = windowWidth; this->windowWidth = windowWidth; this->windowHeight = windowHeight; this->windowTitle = windowTitle; glfwInit(); } MyWindow::~MyWindow() { } GLFWwindow * MyWindow::getWindowHandle() { return this->windowHandle; } void MyWindow::createWindow() { // Use OpenGL 3.3 and GLSL 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Limit backwards compatibility glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Prevent resizing window glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Create window this->windowHandle = glfwCreateWindow(this->windowWidth, this->windowHeight, this->windowTitle, NULL, NULL); glfwMakeContextCurrent(this->windowHandle); } void MyWindow::destroyWindow() { glfwTerminate(); } MyShapes.h
      #pragma once #include <glad\glad.h> #include <GLFW\glfw3.h> class MyShapes { public: MyShapes(); ~MyShapes(); GLuint & drawTriangle(float coordinates[]); }; MyShapes.cpp
      #include "MyShapes.h" MyShapes::MyShapes() { } MyShapes::~MyShapes() { } GLuint & MyShapes::drawTriangle(float coordinates[]) { GLuint vertexBufferObject{}; GLuint vertexArrayObject{}; // Create a VAO glGenVertexArrays(1, &vertexArrayObject); glBindVertexArray(vertexArrayObject); // Send vertices to the GPU glGenBuffers(1, &vertexBufferObject); glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject); glBufferData(GL_ARRAY_BUFFER, sizeof(coordinates), coordinates, GL_STATIC_DRAW); // Dertermine the interpretation of the array buffer glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void *)0); glEnableVertexAttribArray(0); // Unbind the buffers glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); return vertexArrayObject; } MyFileHandler.h
      #pragma once #include <cstdio> #include <cstdlib> class MyFileHandler { private: const char * fileName; unsigned long fileSize; void setFileSize(); public: MyFileHandler(const char * fileName); ~MyFileHandler(); unsigned long getFileSize(); const char * readFile(); }; MyFileHandler.cpp
      #include "MyFileHandler.h" MyFileHandler::MyFileHandler(const char * fileName) { this->fileName = fileName; this->setFileSize(); } MyFileHandler::~MyFileHandler() { } void MyFileHandler::setFileSize() { FILE * fileHandle = NULL; fopen_s(&fileHandle, this->fileName, "rb"); fseek(fileHandle, 0L, SEEK_END); this->fileSize = ftell(fileHandle); rewind(fileHandle); fclose(fileHandle); return; } unsigned long MyFileHandler::getFileSize() { return (this->fileSize); } const char * MyFileHandler::readFile() { char * buffer = (char *)malloc((this->fileSize)+1); FILE * fileHandle = NULL; fopen_s(&fileHandle, this->fileName, "rb"); fread(buffer, this->fileSize, sizeof(char), fileHandle); fclose(fileHandle); buffer[this->fileSize] = '\0'; return buffer; } VertexShader.glsl
      #version 330 core layout (location = 0) vec3 VertexPositions; void main() { gl_Position = vec4(VertexPositions, 1.0f); } FragmentShader.glsl
      #version 330 core out vec4 FragmentColor; void main() { FragmentColor = vec4(1.0f, 0.0f, 0.0f, 1.0f); } I am attempting to create a simple engine/graphics utility using some object-oriented paradigms. My first goal is to get some output from my engine, namely, a simple red triangle.
      For this goal, the MyShapes class will be responsible for defining shapes such as triangles, polygons etc. Currently, there is only a drawTriangle() method implemented, because I first wanted to see whether it works or not before attempting to code other shape drawing methods.
      The constructor of the MyEngine class creates a GLFW window (GLAD is also initialized here to load all OpenGL functionality), and the myEngine.run() method in Main.cpp is responsible for firing up the engine. In this run() method, the shaders get loaded from files via the help of my FileHandler class. The vertices for the triangle are processed by the myShapes.drawTriangle() method where a vertex array object, a vertex buffer object and vertrex attributes are set for this purpose.
      The while loop in the run() method should be outputting me the desired red triangle, but all I get is a grey window area. Why?
      Note: The shaders are compiling and linking without any errors.
      (Note: I am aware that this code is not using any good software engineering practices (e.g. exceptions, error handling). I am planning to implement them later, once I get the hang of OpenGL.)

       
    • By KarimIO
      EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.
      Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?
      Update: No crash occurs if I don't draw, just clear and swap.
      static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // 24Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC = GetDC(windowHandle))) return false; unsigned int PixelFormat; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return false; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return false; hRC = wglCreateContext(hDC); if (!hRC) { std::cout << "wglCreateContext Failed!\n"; return false; } if (wglMakeCurrent(hDC, hRC) == NULL) { std::cout << "Make Context Current Second Failed!\n"; return false; } ... // OGL Buffer Initialization glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); glUseProgram(myprogram); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart); SwapBuffers(GetDC(window_handle));  
    • By Tchom
      Hey devs!
       
      I've been working on a OpenGL ES 2.0 android engine and I have begun implementing some simple (point) lighting. I had something fairly simple working, so I tried to get fancy and added color-tinting light. And it works great... with only one or two lights. Any more than that, the application drops about 15 frames per light added (my ideal is at least 4 or 5). I know implementing lighting is expensive, I just didn't think it was that expensive. I'm fairly new to the world of OpenGL and GLSL, so there is a good chance I've written some crappy shader code. If anyone had any feedback or tips on how I can optimize this code, please let me know.
       
      Vertex Shader
      uniform mat4 u_MVPMatrix; uniform mat4 u_MVMatrix; attribute vec4 a_Position; attribute vec3 a_Normal; attribute vec2 a_TexCoordinate; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { v_Position = vec3(u_MVMatrix * a_Position); v_TexCoordinate = a_TexCoordinate; v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); gl_Position = u_MVPMatrix * a_Position; } Fragment Shader
      precision mediump float; uniform vec4 u_LightPos["+numLights+"]; uniform vec4 u_LightColours["+numLights+"]; uniform float u_LightPower["+numLights+"]; uniform sampler2D u_Texture; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { gl_FragColor = (texture2D(u_Texture, v_TexCoordinate)); float diffuse = 0.0; vec4 colourSum = vec4(1.0); for (int i = 0; i < "+numLights+"; i++) { vec3 toPointLight = vec3(u_LightPos[i]); float distance = length(toPointLight - v_Position); vec3 lightVector = normalize(toPointLight - v_Position); float diffuseDiff = 0.0; // The diffuse difference contributed from current light diffuseDiff = max(dot(v_Normal, lightVector), 0.0); diffuseDiff = diffuseDiff * (1.0 / (1.0 + ((1.0-u_LightPower[i])* distance * distance))); //Determine attenuatio diffuse += diffuseDiff; gl_FragColor.rgb *= vec3(1.0) / ((vec3(1.0) + ((vec3(1.0) - vec3(u_LightColours[i]))*diffuseDiff))); //The expensive part } diffuse += 0.1; //Add ambient light gl_FragColor.rgb *= diffuse; } Am I making any rookie mistakes? Or am I just being unrealistic about what I can do? Thanks in advance
    • By yahiko00
      Hi,
      Not sure to post at the right place, if not, please forgive me...
      For a game project I am working on, I would like to implement a 2D starfield as a background.
      I do not want to deal with static tiles, since I plan to slowly animate the starfield. So, I am trying to figure out how to generate a random starfield for the entire map.
      I feel that using a uniform distribution for the stars will not do the trick. Instead I would like something similar to the screenshot below, taken from the game Star Wars: Empire At War (all credits to Lucasfilm, Disney, and so on...).

      Is there someone who could have an idea of a distribution which could result in such a starfield?
      Any insight would be appreciated
  • Popular Now