Followers 0

OpenGL Time to write rendering engine from scratch

25 posts in this topic

I have a new assignment where my boss wants me to write the complete source code for a simple rendering engine that can load and render standard file formats like OBJ (at least one format) but it needs to be written from scratch.

It's been a while since I wrote one from the ground up (15 years or so), in fact it seems hardly anything in graphics is written from scratch these days. The pay is great so I don't have a problem doing it, but am at a loss for an estimate and wanted to get a consensus from those with experience.

How long would you estimate it would take to write an OpenGL program that can load say OBJ files and render models without fancy shaders?

Also, what file format is most straightforward to load and render?

Thanks in advance. Edited by bigneil
-2

Share on other sites
I agree, it will take time to learn all the stuff necessary to write a serious and correct viewer that works according to the endless amount of specifications you'll need to know.
But, feel free to ask anything in here if you run into any problems..
I would start with GLFW for the openGL window, and go from there, as it is multiplatform (win, linux, mac), and handles the window, inputs and swapping (including vsync) for you.
Unless you also have to do that by hand
1

Share on other sites
I'd be extremely careful as the goal is not clearly defined. I use AssImp for the loading yet I'd find hard to take less than 5 working days. But perhaps my definition of "without fancy shaders" is different from yours. Edited by Krohm
1

Share on other sites
As L. Spiro say, it´s personal. And if you dont have any experiance in coding with either Dx or GL it will probably take a while to figure out how things work.

Use Assimp, it´s easy, it´s good, it´s fast and honestly saved me alot of work and time. it allso supports a ton of formats.
estimate to one month. thats a good start amount, you have room to develop, and to fix bugs, and to correct or rewrite stuff if you are forced to.
1

Share on other sites
Generally unsure of myself? 15 years rusty?

And it would take Spiro 2 days and it would take me 2 months?

Who is Spiro trying to impress? A group of anonymous computer nerds?

FYI I've programmed OpenGL every day for the past 15 years, and patented my own rendering system in the process. My own product already served as a rapid prototyping tool and I solved their actual problem in my first few hours.

It just happens they want the source code (a license of which I sell for $250K). I'm just pointing out that people don't usually write rendering engines from scratch anymore (the one I wrote in 1997 is still working fine thank you), and if someone tells you they can write a rendering engine from scratch in 2 days they are lying. -24 Share this post Link to post Share on other sites [quote name='bigneil' timestamp='1351866936' post='4996539'] it would take Spiro 2 days and it would take me 2 months? [/quote] I don’t know. How long [i]would[/i] it take you? That is what we are trying to determine. [quote name='bigneil' timestamp='1351866936' post='4996539'] I wwebsite as on the internet [/quote] You obviously know more about yourself than any of us, but put that aside for a moment and read your post and then my reply. If you can’t handle the answer, don’t ask the question. If you do ask the question, you should provide all of the necessary information. When estimating how long it would take you to complete a task in OpenGL, it would be a good idea to mention any experience you have in OpenGL up-front. It’s generally assumed that if you come here to ask a question, you [i]want[/i] to find people who are more experienced than yourself so you can get help from them. If this wasn’t your thinking, then what was? Did you hope to find a bunch of people saying, “It would take me 3 weeks,” so that you could say to yourself, “What a loser, I am so much better than him or her”? It sounds as though you already know the answer, so good luck with your project. L. Spiro Edited by L. Spiro 2 Share this post Link to post Share on other sites I'm not sure how "It's been a while since I wrote (a rendering engine) from the ground up" was interpreted as "it's been a while since I programmed graphics (in any capacity)", or who wouldn't take "you sound rusty and unsure of yourself" as less than insulting, but I appreciate the advice. Thanks everyone. -6 Share this post Link to post Share on other sites Because I was just tasked with writing a rendering engine from scratch I wanted to get a consensus on what people who have written rendering engines more recently thought. In the end I decided to whittle down my own code since it works perfectly (and recompiles in 6 seconds to all you A-holes who write programs that take 2 hours to compile (see Electronic Arts). But man, I forgot what a bunch of d*uche b*gs are on this site. Members here (what an appropriate term) pride themselves on their blog rating here and you'll never find a site more likely to neg you for one post that doesn't stroke their ego. Try saying you don't like Goto for example - they'll neg you all the way to negative 1000. But try asking an advanced question about parametric surfaces and you'll get crickets. Most of the people here with high ratings don't actually have computer science jobs (or formal experience) which is why they have so much time (and why they are so bitter). Worse, they provide best-case scenario estimates - an enormous disservice to themselves, coworkers and the industry. A wise man once said "The more I know the less I understand" - and members here understand everything. If you've worked in the industry you know you'll never find smarter people who are willing to do exactly what they are told (by their boss, the FDA and the TSA) - Developers in a crisis will (according to Meyer Briggs) "go with what the group does". Oh well, I'd rather be making$90 an hour programming OpenGL for my own business than to have a high db rating, but if you make less be sure to neg me.

Anytime you do something worthwhile you're going to offend someone.
-11

Share on other sites
Whoa whoa whoa
[quote name='L. Spiro' timestamp='1351813476' post='4996360']
[b]If[/b]...
[b]If[/b]...
[b]If[/b]...
[b]If[/b] you are generally unsure of yourself (and it [b]sounds[/b] as though you are), I would say you should give yourself no less than a month, maybe up to 2.

[b]Because of the wide range of skills and experiences, I am not sure how helpful any of our answers would be[/b].
[/quote]
1) I don't believe LS was tearing you down or diminishing your character. And I'm pretty sure the way you reacted to LS and similar answers set this thread downhill. Clarification on your part probably would have went a long way.
2) [i]Plenty[/i] of people here don't like goto (unless absolutely positively necessary, which it usually isn't).
3) I don't believe you can get a negative rating - perhaps I am wrong about that one though.

Please try to reconsider your perspective on all this - it's not what you think it is.
1

Share on other sites
[quote name='achild' timestamp='1352238672' post='4998210']
3) I don't believe you can get a negative rating - perhaps I am wrong about that one though.
[/quote]
No you actually can. Lowest I've seen so far is -350 or so. Not that ratings matter that much anyway. I've come to the conclusion that the thread creator is a troll, and you know what they say about trolls. Edited by Bacterius
1

Share on other sites
I can only second L Spiro here.

You ask a question, which it must be assumed was well-intentioned and in good faith.
You get some answers that also read as well-intentioned and in good faith.

From there it seems that you didn't like the answers you got and the resulting conflagration borders on thermonuclear war. Not good.

I'm not saying that you're obliged to like the answers, but there is such a thing as basic manners - people have freely and willingly given of their own time here.

One can only answer a question based on the information contained in that question; if the answers recieved are believed to be inadequate or otherwise lacking then there is obviously a communication deficit of some kind to be addressed. Strikes me that it would have been far more productive to address that deficit than to engage in flaming out.
2

Share on other sites
[img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img]
1

Share on other sites
[quote name='Caffeware' timestamp='1352320584' post='4998571']
[img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img]
[/quote]

Excellent Caffeware - I downloaded it and it ran instantly - this is how all software should be written!
0

Share on other sites
Yes! I almost achieved my negative rating!

This shows what a farce it is.

When you're a 20 year veteran of the 3D graphics industry and already worked on Madden Football, Far Cry, Doom, Descent and other games, the rating system doesn't disprove you, you disprove the rating system. Edited by bigneil
-3

Share on other sites
"Strikes me that it would have been far more productive to address that deficit than to engage in flaming out."

It's the forum that flames out. I was once a member for years and had a rating of 400 or so, then when I said I didn't like Goto my rating went all the way to -400 - OVER ONE THREAD. Edited by bigneil
-1

Share on other sites
I really do not get why you're reacting this agressively to people's reactions, there was no need for any agression, nobody tried to flame you or attack you in any way whatsoever. You got some valid answers to your question, there may have been some misunderstandings and miscommunications but there's no reason to suddenly react the way you did.
You claim to be an industry veteran of 20 years, if that's true you might want to think about acting somewhat more like an adult then in this situation instead of starting to flame and trying to profile yourself as superior to everyone else because of the projects you have done or (of all things) the compile times you get.
0

Share on other sites
[quote name='bigneil' timestamp='1352410597' post='4999033']
When you're a 20 year veteran of the 3D graphics industry and already worked on Madden Football, Far Cry, Doom, Descent and other games, the rating system doesn't disprove you, you disprove the rating system.
[/quote]
I am really getting tired of you and your inferiority complex. You asked a question hoping to find people with more experience than you on a given subject.
I answered because that subject is exactly down my ally. When I go to work, I make a game engine (unless I am going to my other job that is). When I get home, I make a game engine.

[i]Game[/i] engines aren’t [i]rendering[/i] engines, but it just so happens that my current task at work is the rendering part, and on my own engine I am currently working on the rendering part.
[quote name='bigneil' timestamp='1352410597' post='4999033']
Because I was just tasked with writing a rendering engine from scratch I wanted to get a consensus on what people who have written rendering engines more recently thought.
[/quote]
And I am exactly the person you wanted to answer this question. [i]I am writing a damned book about rendering/loading graphics files/etc. as we speak.[/i]

Suddenly you are offended that someone is better than you at this task, yet why wouldn’t I be? It’s what I do all day every day—whatever you do all day every day probably makes you better at that than I am.
So your inferiority complex kicks in and you have to make up for it in other ways—salary, past projects, status, etc.
I have been extremely kind up to this point, having passed up numerous chances to put you in your place, but here is the deal: [i]You don’t impress me.[/i]
There are people here who do, but you will never be one of them. They impress due to their skills and professionalism. Your salary, past projects, and status as a business owner are [b]not[/b] impressive. Once again I am leaving it at that instead of taking you down a few notches, although you do deserve to be put in your place. I can at least say that based on your salary, past projects, and status as a business owner, you have no place to brag, so listing these things as an attempt to make up for your shortcomings in skill only make you out as someone that much more desperate to have lived a better life. Just stop trying to make yourself more than you are, because I can promise you that no respectable person I have ever met has made the kinds of posts you have made, trying to prove themselves to some other random person online. Each time you do so just makes you much less of an impressive person and much more like the kind of person who wishes he or she was more than he or she actually is.

[i]You[/i] are what’s bringing this site’s quality down.
You only come here to flame and brag about yourself, and this topic serves absolutely no purpose to anyone who stumbles upon it in the future. It starts with a very vague question and quickly becomes a 1-man flame-war. Then you make it clear that your goal is only to get a negative reputation (I still haven’t touched your reputation, by the way).
I am not a moderator here, but it is [i]obvious[/i] that if you don’t take a contributory tone starting from your very next post, [i]you will be banned[/i].

L. Spiro Edited by L. Spiro
2

Share on other sites
At this point I need to chime in about reputation.

Reputation is NOT there to stroke anyone's ego. Any member of this site with sufficiently high reputation is most definitely NOT getting an internet hard-on (pardon the choice of phrase, couldn't think of a better way of putting it) from it, because they understand the purpose of the system.

The reason for reputation is to act as a service to the community. People can identify the good answers to questions, the ones that are most likely to be the right answer or to at least shove them in the right direction.

A good, fully functioning member will [i]welcome[/i] negative reputation as much as they welcome positive reputation, because they will see negative reputation as something that puts their own previously held assumptions to the test. Because they understand that no matter how much one is experienced, no matter how much one knows, learning is a continuous process.
1

Share on other sites
As a slight topic digression, what is the state / benefits to your engine Spiro? I'm always interested in hearing what goes on
As a member who frequents another forum devoted to a specific software, I hope I can provide something in the nature of an opinion.
I myself do not work in rendering engines. I have little experience, yet enough to understand that it can become a quickly all-encompassing task.
The issue here is that you failed to address a generic opening. This is the cause of the troubles. If you have a genuine question, ask it again, and perhaps apologise if you feel that you have overreacted. If you feel that this is unfair, then lest this topic be useful to others it should be left. Best of luck to all.
0

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

Followers 0

• Similar Content

• 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
#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.

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

• 12
• 28
• 14
• 11
• 34