Sign in to follow this  
DarkBalls

Creating a window in windows using only int main()

Recommended Posts

DarkBalls    100
I'm creating a game engine right now with my team but I want to dump SDL now. Our engine is quite good because we can now create some simple games on it. So I created a window using the usual int WINAPI WinMain(). But because I want our engine to be like those other outside that is OS independent, I've created a class that will check what OS the developer is using then use the necessary function to load/create a window. Now my problem is, I don't know how to create a window in windows, for now because I'm going to study linux also maybe after this, using only the int main() function. Thanks DarkBalls

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
You can't.
You must have an OS-specific file, or a #define that says the OS, and let the entry-point be the correct main function. Then from that call your own function, GameMain or something, in which the OS-independent stuff takes place.


#ifdef WINDOWS
int WINAPI WinMain(..) {
GameMain();
}
#elif LINUX
int ...() {
GameMain();
}
#endif

void GameMain() {
}

Share this post


Link to post
Share on other sites
DarkBalls    100
@Erik Rufelt
How can SDL do those thing? Does it have any libraries that define everything what to do. I don't want to use sdl on our engine really. I want to have our own. If only we know the steps how to do it, we will do it really.

@scottrick49
Still I need to set the subsytem to windows. But thanks for the help.

@Antheus
Thanks for the help but I don't want to use any libraries out there.

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:

Thanks for the help but I don't want to use any libraries out there.

That is the kind of mentality that makes mediocre engines.

All the big companies use libraries. Who wants to pay programmers to write physics code when you could license Havok and concentrate on the stuff that makes your game unique.

Write games, not engines.

Quote:

How can SDL do those thing? Does it have any libraries that define everything what to do. I don't want to use sdl on our engine really. I want to have our own. If only we know the steps how to do it, we will do it really.

SDL has a huge number of code paths for many different platforms. SDL_SetVideoMode() is a work of art, hiding an immense complexity from you.

Take a look at the SDL source to see how they did it.

I believe it has been used in some quite serious software, IIRC Unreal 2004 and Doom3 both use SDL for the Linux ports. What do you think you will gain by dumping SDL? You spend god knows how long writing code that essentially sets up a window for you, and meanwhile your game is no closer to being finished than when you were using SDL.

Share this post


Link to post
Share on other sites
dmail    116
Quote:
Original post by Erik Rufelt
You can't.
You must have an OS-specific file, or a #define that says the OS, and let the entry-point be the correct main function. Then from that call your own function, GameMain or something, in which the OS-independent stuff takes place.

*** Source Snippet Removed ***

Rubbish you can use main as the entry point in windows and still create a window, WinMain does not create a window it is just an OS specific entry point which by default does not have a console window.

Quote:
I want to dump SDL now

Why do you want to discontinue using that library?
Does it not fulfil your requirements? if so what are they, maybe another library for instance SFML as Antheus pointed out maybe better.

Quote:

Now my problem is, I don't know how to create a window in windows, for now because I'm going to study linux

So you neither know how to create a win32 or X11 window, well it does not take much knowledge to create them but this is not everything which SDL does for you.

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
Quote:
Original post by DarkBalls
@Erik Rufelt
How can SDL do those thing?


I'm pretty sure SDL does as I wrote in the example, they probably have something like that in a header. At least that's how many libraries do it.

Share this post


Link to post
Share on other sites
DarkBalls    100
Will you please stop saying "Write Games not engines". I'm here to ask for help on how to open a window using only int main() and not using any libraries at all and not about the engines!

So, if you are telling me to write games not engine, just keep it in yourself. That's what you want. So be it. Just shut the fuck up! But I'll never follow you. If you want to be just a game developer who code games or actually don't know how the graphics engines works. Ok, that's what you want to be. Go for it!

We are creating a 3D engine because we love it, we love graphics, we love algorithms, we love trees, we love shaders, and we love math. So only "Mediocre engines"? Why the hell are you comparing the physics engine on just windowing? Are you in drugs? You're insane really. We are focus only in 3D graphics not everything else. If we are going to create a game in the future, we might use Havok or PhysX.

And honestly, I think you didn't understand the article about "Write games not engine". I think the author should put "FOR NOW" in the end if you really understand his conclusions.

I'm really pissed off on those people who really think they are so smart. Ok, you're so smart now because you're not like me who is so stupid(for you because of what you believe) that creates a 3d engine, and you are using our engine. lmfao.

Share this post


Link to post
Share on other sites
dmail    116
Quote:
Original post by DarkBalls
Will you please stop saying "Write Games not engines". I'm here to ask for help on how to open a window using only int main() and not using any libraries at all and not about the engines!

Woot hardcore, why not use assembly! O wait what about the platform SDK's and ...?

Quote:
Original post by DarkBalls
Unadulterated drivel.
... and you are using our engine. lmfao.

Yes but you have to make it first.

Seriously take a step back, take in a deep breath and consider if this is what you really want to do. Please answer the question
Quote:

Why do you want to discontinue using that library?

Share this post


Link to post
Share on other sites
rip-off    10976
What a reasonable response.

To be perfectly honest, if you are smart enough to write a fancy 3D graphics engine I would have imagined that you would be able to find out how to create a window without our help...

So which is it?

And remember, this question is still open:
Quote:

What do you think you will gain by dumping SDL?

Share this post


Link to post
Share on other sites
DarkBalls    100
@dmail

Quote:

Rubbish you can use main as the entry point in windows and still create a window, WinMain does not create a window it is just an OS specific entry point which by default does not have a console window.


If I understand what you said correctly, I can create a window using only int main() and subsystem in console?

Quote:

Why do you want to discontinue using that library?
Does it not fulfil your requirements? if so what are they, maybe another library for instance SFML as Antheus pointed out maybe better.


I'm just using SDL's windowing and input and using OpenGL to render 3d graphics. So I think making my own for that will not really a big job, I think.

Quote:

So you neither know how to create a win32 or X11 window, well it does not take much knowledge to create them but this is not everything which SDL does for you.


I know how to create a win32 window but not yet in linux. But I have a linux installed on my virtual machine.

@Erik Rufelt
Quote:

I'm pretty sure SDL does as I wrote in the example, they probably have something like that in a header. At least that's how many libraries do it.


If I didn't find any way on how to create a window using int main() and subsystem console, I'll just leave to that for now.

@rip-off

I'm not having a problem with window really. I'm looking for a way on how to create a window using int main() and subsystem console just like SDL does.

Share this post


Link to post
Share on other sites
BreathOfLife    188
I know its not exactly what you want to hear (Id get used to the feeling) but its true. Frustration in normal, but detrimental to the cause.

Sure, you can avoid libraries and still make your 3d engine, but you wont spend any time working on the 3d engine, you'll end up spending alot of time working with drivers and low level stuff, stuff which you wont be able to do as well as libraries provide, in addition to spending ALOT of time on it.

OpenGL and DirectX and SDL cover most of that for you. They know how to get the hardware info required, and use that to know how to send the right messages to the drivers in the correct fasion.

You use those libraries when you make an engine, you dont rewrite them and then make an engine with your driver handling code. You still need to learn an aweful lot about graphics programming to use them effectively.

You take this as shattering your dreams it seems, we're trying to tell you that taking the path you're on for too long is going to shatter them as well. If you really, really want to learn graphics stuff, learn DirectX and OpenGL. The pair will teach more then you could want on the subject.

Share this post


Link to post
Share on other sites
SiCrane    11839
Quote:
Original post by DarkBalls
If I understand what you said correctly, I can create a window using only int main() and subsystem in console?

Just try it. If it doesn't work, then make a post about it.

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
If you want a console you can most definitely create it with only int main(), have you even tried it??
It _just works_, nothing to do, nothing to add, just type

int main() {
CreateWindow(...)
}

and you have your window, no problems, no nothing.

I assumed, since you posted a question like this, that you did not want a console or that you had already tried it and it didn't work without WinMain.
You'll never finish any engine if you need answers to small irrelevant questions like this before you even start.

Share this post


Link to post
Share on other sites
dmail    116
Quote:
Original post by DarkBalls
@dmail
If I understand what you said correctly, I can create a window using only int main() and subsystem in console?

You have me confused now. Are you wanting to create a console window or win32 window? You can create a console window from WinMain using AllocConsole but this does not seem to be what you are asking. Yes you can create a win32 window using the entry point main. GetModuleHandle can give you the HINSTANCE to the process.

Quote:

I'm just using SDL's windowing and input and using OpenGL to render 3d graphics. So I think making my own for that will not really a big job, I think.

Ok lets quickly think this through, here is what you need
Cross platform window creation.
Cross platform window events.
Cross platform joystick handling.
Cross platform OpenGL and window binding.
Cross platform OpenGL extension loading.
This is only a very small fraction of what SDL provides.

Quote:

I know how to create a win32 window but not yet in linux. But I have a linux installed on my virtual machine.

This just confuses me more :) By the way you will not be able to have graphic acceleration in a virtual machine.

Quote:

Quote:

@Erik Rufelt
I'm pretty sure SDL does as I wrote in the example, they probably have something like that in a header. At least that's how many libraries do it.


If I didn't find any way on how to create a window using int main() and subsystem console, I'll just leave to that for now.

I do not know how helpful this will be but in a nutshell this is how SDL does it on windows.
*It uses the preprocessor to rename entry point
*Defines its own entry point
*Sets up global states
*Then calls your entry point which it renamed.

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:
Original post by DarkBalls
@BreathOfLife

I'm using only SDL's windowing and input, so is it really reasonable to use it or write the code myself?


Have you a compelling reason not to use something that you already have working? Do you think using SDL will be a problem? Does it not support some feature you absolutely rely on having?

The whole point of SDL is to set up a rendering context for you, handle input and then get out of your way. It sounds like the perfect solution for someone in your position, with your (mostly assumed) requirements.

Share this post


Link to post
Share on other sites
DarkBalls    100
Oh now it works. Thanks to scottrick49 and Erik Rufelt. I just forget to change the subsystem to console. stupid me. Now it is working fine. Thanks guys.

Oh, what a tough forum really. I should just ask on a c++ forum or maybe tell that it is not for a 3d engine.

But anyway, thanks for the help.

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:
Original post by DarkBalls
Oh, what a tough forum really. I should just ask on a c++ forum or maybe tell that it is not for a 3d engine.


Most forums will look down on childish tantrums like your explosion in the middle of this thread. Its an attitude thing simply. I expect you to be reasonable.

If you has said "I'm sorry, but I am really want to do this myself", then that is fine. But the profanity was unnecessary and inexcusable. Learn to restrain yourself, to not read too deeply into what other people type. This is a text only medium, without the subtle cues of body language to give you a hint about intent. I was trying to be helpful, as are the other members of this forums. Not trying to attack you or something, which is what you appeared to be responding to.

FWIW, I still think you are making a mistake by pursuing this path.
Quote:

What do you think you will gain by dumping SDL?

Quote:

Why do you want to discontinue using that library?

The fact that you cannot (or will not) answer the above two questions (which, IMHO, might well amount to the best help you got in this thread) indicates that this is some kind of "not invented here" tangent that you will only regret later.


Quote:

But anyway, thanks for the help.

You are most certainly welcome [smile]

Share this post


Link to post
Share on other sites
Nitage    1107
I prefer something like this:

//main.cpp - compiled on all platforms
int main()
{
//whatever
}

//main.win32.cpp - compiled only when targetting windows
extern int main();

int WINAPI WinMain(..)
{
main();
}

Share this post


Link to post
Share on other sites
Zahlman    1682
On this forum, helping people takes priority over answering the questions that have actually been asked. As the question-asker, you must accept the possibility that you are not asking the right questions, if you want to get anywhere. You are not required to pay for any of this, so you are not in control of what you get back.

Quote:
Original post by DarkBalls
Will you please stop saying "Write Games not engines". I'm here to ask for help on how to open a window using only int main() and not using any libraries at all and not about the engines!


If you are not taking advantage of existing code to do things, and you are trying to do those things, then you have to write the code to do those things. If those things aren't directly required for "writing the game", then they are a part of "writing the engine".

We understand what you're asking about. The point is that you are wasting your time by attempting to do it. You can't open the window any better than the library can. Opening the window is platform-specific, so you will have to write the code for each platform and recompile for each version, arranging for main() to call to whatever. Excpet that on Windows, you'll probably have to use WinMain() instead of main() anyway because that's just how Windows works.

The point of using a library is that the library already understands how to handle these things.

You haven't yet given a reasonable reason for why you "want to dump SDL now". We're giving you one for not dumping it.

Quote:
So, if you are telling me to write games not engine, just keep it in yourself. That's what you want. So be it. Just shut the fuck up! But I'll never follow you.


Nice attitude to present towards the people you're depending on for help, yeah?

Quote:
If you want to be just a game developer who code games or actually don't know how the graphics engines works. Ok, that's what you want to be. Go for it!


Being able to get the window set up on each platform has nothing to do with understanding how to do graphics. Understanding how to translate the source into machine code has nothing to do with writing the game, either. That's why we use a compiler. It's the same thing. If you want to try to scrape everything out with a hex editor, go ahead. But it'd be your own fault if you worked at that for months and still didn't have a working "Hello world".

Quote:
We are creating a 3D engine because we love it, we love graphics, we love algorithms, we love trees, we love shaders, and we love math. So only "Mediocre engines"?


That mentality leads to writing mediocre engines. At any rate, it leads to writing worse engines than you're capable of.

Quote:
Why the hell are you comparing the physics engine on just windowing?


You're the only one making such a comparison. He didn't even say anything about physics.

Quote:
Are you in drugs? You're insane really. We are focus only in 3D graphics not everything else.


Then focus on what you're focussed on. Hint: making nice 3D graphics has nothing to do with getting the window set up to display them in.

Quote:
If we are going to create a game in the future, we might use Havok or PhysX.

And honestly, I think you didn't understand the article about "Write games not engine". I think the author should put "FOR NOW" in the end if you really understand his conclusions.


I'm not convinced that you've understood the article. If you took the time to read the article and understand it, you'd have calmed down a bit.

Quote:
I'm really pissed off on those people who really think they are so smart. Ok, you're so smart now because you're not like me who is so stupid(for you because of what you believe) that creates a 3d engine, and you are using our engine. lmfao.


I can barely even make any sense out of that. This is not a real-time chat; edit your post before you submit it.

But I doubt rip-off - or anyone here - is actually using your engine. Who are you, anyway?

Share this post


Link to post
Share on other sites
phresnel    953
Quote:
Original post by DarkBalls
stupid me.

Dunno, maybe. But I prefer to call you overheated and unexperienced. Otoh, those are stupid who curse the counsel of the elders.


Quote:
And honestly, I think you didn't understand the article about "Write games not engine". I think the author should put "FOR NOW" in the end if you really understand his conclusions.

No, reading and reflecting two words is not understanding the conclusion.

Also, if your intention is really to write an engine, the statement "Write games not engines" can easily be transformed to "Write an engine, not device drivers", or "Write a device driver, not an operating system".


Quote:
If you want to be just a game developer who code games or actually don't know how the graphics engines works. Ok, that's what you want to be. Go for it!

Somehow it makes me nervous that I am currently no engine-developer, not even a game-developer. Heck, I am just a frickin' applications developer boohoohoooo [sad]

Jokes aside: DarkBalls, as you are a hardcore programmer, have you ever considered participating in X11 device driver development? You nearly get to the raw metal, should be the right thing for you. Don't be just a userspace graphics programmer. Free yourself.


Quote:
We are creating a 3D engine because we love it, we love graphics, we love algorithms, we love trees, we love shaders, and we love math. So only "Mediocre engines"?

If you love all those, why bother writing low level code or assembly to just show a window?


Quote:
... and you are using our engine.

No, I am not.

Share this post


Link to post
Share on other sites
Antheus    2409
Hey, I started a flamewar....

In my defense, the reason for linking SFML was to suggest looking at its source to see how an IMHO well-written API accomplishes that.

Share this post


Link to post
Share on other sites
phresnel    953
Quote:
Original post by Antheus
Hey, I started a flamewar....


Not really, it was the big bang's fault ;)

edit: That is, if we take it to an extreme.

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