Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to make my own gui using opengl and SDL and C++ or whateva? :)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 PGSCreativeDirector   Members   -  Reputation: 48

Like
0Likes
Like

Posted 16 September 2011 - 04:06 AM

hello im a novice at programming tired of crap and wanting to be less crap by creating things that i can work with but for me too do that i need to know where to start because everything is so dam non logical in the world of coding when theres no explanations or tutorials simplfied word by word on how to do what i want

so im assuming you want to know what i want :P

well this is it

How do i make a Graphical User interface that works ontop of OpenGL and SDL ?

no i do not want to use GLUT or freeGLUT or CEGUI or AntTweakBar

i want to make my own :)

And where did you find information on it because i cant find anything using google ("bet people do that to make it more harder for programmers") * coughs

and i dont want to hear how complex it is ,etc i just want somewhere to start that will give me anuff know how to do it for myself thanks
i really tryed hoping that i didnt have to ask but i guess theres no where else to go so

i aslo wanna state that i learn by learning word for word :) not from massive statements with comments which is just not flexible anuff imo

and ! :D i may sound like i dont know what im doing and thats because i do im guesser / reader :D it works

also i dont want to sound like im bashing just annoyed :)

Sponsor:

#2 retroworld   Members   -  Reputation: 164

Like
0Likes
Like

Posted 16 September 2011 - 04:39 AM

first you need to make objects such as buttons and menus.
If you're just doing this in SDL, you can blit these to the screen and when you flip the screen they will appear.
If you're using opengl with SDL, you need to make objects/plates and display them in ortho mode.

If you don't know what I am on about, you should learn SDL and OpenGL and it will all become clear.



#3 PGSCreativeDirector   Members   -  Reputation: 48

Like
0Likes
Like

Posted 16 September 2011 - 04:42 AM

so i create a class with a bunch of objects in it using what win32? :) or something else what do i use

#4 SimonForsman   Crossbones+   -  Reputation: 6061

Like
0Likes
Like

Posted 16 September 2011 - 05:36 AM

so i create a class with a bunch of objects in it using what win32? :) or something else what do i use


For simple things like buttons you really only need to draw a textured quad , change the texture when the mouse moves over that quad or when you click on it (up to you how advanced you want it).

You don't need anything other than SDL (for mouse and keyboard events) and OpenGL (for drawing) to make your GUI.

More advanced controls are obviously more complex and a complete GUI system with customizable controls is a huge undertaking. (Most games don't really need a complete GUI system though, most will do just fine with a few buttons, sliders and input boxes)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#5 haegarr   Crossbones+   -  Reputation: 4176

Like
0Likes
Like

Posted 16 September 2011 - 06:16 AM

* You have to define what principles the GUI should follow: A traditional point-&-click GUI? A crossing based GUI? A ZUI? Or what else ...

* A UI does not only consist of a graphical front-end but also has to deal with user input. What input devices do you want to support? Some principles expect a particular kind of input device to be in use.

* Decide what kinds of "widgets" (or whatever the building blocks will be) you need to support.

* Shall internationalization be supported? Which text systems shall be supported?

* Clarify how the UI affects the application data model and how it is supported to read from the data model as well. Do you want to use data binding? Callbacks? Delegates? Signals and slots? Events?

* Shall the GUI be resolution independent?

* Shall the GUI support theming as is often desired (for GUI middleware) for games?

* Shall the GUI be animatable as is often desired for games?

* Shall the GUI (or at least input) be run in an own thread to be e.g. responsive independently on the frame rate? (Okay, this is really advanced ;))


All this (and probably more) has an influence on answering the OP. "Making" a GUI in the sense of rendering is far after planning it.

#6 PGSCreativeDirector   Members   -  Reputation: 48

Like
0Likes
Like

Posted 16 September 2011 - 06:24 AM

il go the opengl route then :) be much funner that way as well

#7 mrchrismnh   Members   -  Reputation: 82

Like
0Likes
Like

Posted 16 September 2011 - 06:54 AM

I would suggest some gui coding in java; you'll have better luck rolling your own gui components oce you've seen how they implement theirs.


"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy


#8 mdwh   Members   -  Reputation: 856

Like
0Likes
Like

Posted 19 September 2011 - 06:28 AM

Experience of application GUI programming is certainly a good idea, to see how toolkits should be properly implemented - though he might as well try something in the language he's using rather than (possibly) learning a whole new one. For example, for C++, I'd recommend Qt.
http://erebusrpg.sourceforge.net/ - Erebus, Open Source RPG for Windows/Linux/Android
http://homepage.ntlworld.com/mark.harman/conquests.html - Conquests, Open Source Civ-like Game for Windows/Linux

#9 SiS-Shadowman   Members   -  Reputation: 359

Like
0Likes
Like

Posted 19 September 2011 - 06:59 AM

I would also recommend to first see how other GUI systems are implemented and then try to roll your own. I'm currently doing the same thing, mostly borrowing concepts from Qt and WPF.

You basic block would most likely be a Widget or Control which has several parameters (position, size, etc.. come in mind). I would keep the inheritance hierarchy very small (most widgets directly inherit from widget in my case) and perfer composition instead. Depending on your needs this will be a huge amount of work (I'm currently two weeks in and have a plan for at least another month of work).



#10 speciesUnknown   Members   -  Reputation: 527

Like
1Likes
Like

Posted 19 September 2011 - 08:07 AM

hello im a novice at programming tired of crap and wanting to be less crap by creating things that i can work with but for me too do that i need to know where to start because everything is so dam non logical in the world of coding when theres no explanations or tutorials simplfied word by word on how to do what i want

so im assuming you want to know what i want :P

well this is it

How do i make a Graphical User interface that works ontop of OpenGL and SDL ?

no i do not want to use GLUT or freeGLUT or CEGUI or AntTweakBar

i want to make my own :)

And where did you find information on it because i cant find anything using google ("bet people do that to make it more harder for programmers") * coughs

and i dont want to hear how complex it is ,etc i just want somewhere to start that will give me anuff know how to do it for myself thanks
i really tryed hoping that i didnt have to ask but i guess theres no where else to go so

i aslo wanna state that i learn by learning word for word :) not from massive statements with comments which is just not flexible anuff imo

and ! :D i may sound like i dont know what im doing and thats because i do im guesser / reader :D it works

also i dont want to sound like im bashing just annoyed :)


There are a few ways of doing this. The level of complexity and the amount of work that goes into it depends on what features you want. What will your GUI consist of? Screens, buttons, labels, and toggle switches are simple to implement yourself.

Think up a couple of use cases.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

#11 Soaps79   Members   -  Reputation: 116

Like
0Likes
Like

Posted 20 September 2011 - 10:30 AM

I've been on this mission for a long time as well. One can't argue with the suggestions to use other GUI libraries to get a handle on different API's. Once I did this, I found the GWEN UI. You can grab the entire codebase, I learned tons sifting through it.

http://code.google.com/p/gwen/

#12 Infernal-rk   Members   -  Reputation: 135

Like
1Likes
Like

Posted 21 September 2011 - 04:38 PM

I have to point out. Maybe you should design you hud and menus for your game prior to making gui code. That's if you are making a game. This will allow you to be very precise about the feature set you require.
From there you can design it to be extendable for future generic use in any game you want to make but for now, you'll have the feature set you need for your game.

UI systems can get very complicated and then require alot of support assets (images, video, icons) to make use of their more advanced features. You run the same risk as people sitting down and coding generic game engines instead of the engine they need for their specific game.

A prime example: Will you need Scroll bar functionality? really? will you actually need it?

it's a default part of most UIs you see in applications, but in your game.. will there actually be enough stuff in any menu or text field requiring scrolling?

#13 jbadams   Senior Staff   -  Reputation: 18019

Like
1Likes
Like

Posted 22 September 2011 - 05:20 AM

This site walks through the basics of creating an immediate mode GUI using SDL -- take a look, it might be what you're after!

#14 T e c h l o r d   Members   -  Reputation: 186

Like
0Likes
Like

Posted 23 September 2011 - 05:54 AM

HI PGSCreativeDirector,

I'm a advocate for developing your own GUI. If you consider the notion that the entire 3D Game-world is a Graphical User Interface, you can apply your techniques developed for GUI event handling, messaging, and process optimization to other game entities. I'm currently developing my 15th iteration of a GUI taking an Entity/Component Approach (Ref 1,2,3) .

I'm developing my 2D/3D GUI system using OIS for input, Bullet for collision detection, OGRE (DX/OpenGL) for rendering. I use a Entity/Component Model in which Widgets are containers that loosely couple input, collision, and visual components. You can combine these the components in different variations to create different types of widgets, and layer Widgets on top one another to create more complex Gadgets (composite Widget).

If theres any advice I can offer, I would say that the input and collision components are the primary mechanism for User-Interaction. The visual component is secondary, a representation controlled by the state of the interaction. So, I'd suggest you solve how to 1) manage input , 2) create collision shapes, 3) render visuals, respectively.

#15 Gl_Terminator   Members   -  Reputation: 448

Like
0Likes
Like

Posted 23 September 2011 - 06:48 AM

You should start as i did
you have a manager class that has a list of screens and only renders and unpdate the selected screen, create a control base class that has a rectangle(all controls are rectangles) and delegates to any event you want to add, this base class has to have a method update a a method draw, in the method update check if the mouse is on the rectangle and fire the added events here is a sample in c#, if you don't want to use glut for text use glFonts.



using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;


namespace ShadowEngine.VisualControls
{
	public delegate void OnClick();
	public delegate string Function();
	public delegate string FunctionParameter(object objeto);


	public abstract class Control
	{
    	protected string accesibleName = "null";
    	protected OnClick onClick;
    	protected Rectangle areaRectangle;
    	protected Color fontColor = Color.White;
    	protected int zOrder;
    	protected int displayList;
    	protected IntPtr textFont;
    	protected bool discard;

    	public string Name
    	{
        	get { return accesibleName; }
    	}
	}
}


using System;
using Tao.OpenGl;
using System.Drawing;
using ShadowEngine.Sound; 

namespace ShadowEngine.VisualControls
{
	public class Button : Control, IControl 
	{
    	bool isPressed;
    	string text = "";
    	string textHoverS, texPressedS, texNormalS;
    	int textHover, texPressed, texNormal, texCurrent;
    	int textWidth;
    	Vector2 textPosition = new Vector2(0, 0);
    	Vector2 buttonPos;
     	

    	public Button(Rectangle rectangle, string text, OnClick onClick)
    	{
        	buttonPos.X = rectangle.X;
        	buttonPos.Y = rectangle.Y;   
        	base.zOrder = 0; 
        	this.text = text;
        	this.areaRectangle = rectangle;
        	base.onClick = onClick;
        	texNormalS = "normal.jpg";
        	texPressedS = "pressed.jpg";
        	textHoverS = "hover.jpg";
        	texCurrent = texNormal;
        	textWidth = Sprite.FontWidth(Glut.GLUT_BITMAP_HELVETICA_18, text);
        	textPosition = new Vector2(areaRectangle.X + (areaRectangle.Width - textWidth) / 2,
                                    	areaRectangle.Y + ((areaRectangle.Height - 15) / 2) + 14);
        	this.textFont = Glut.GLUT_BITMAP_HELVETICA_18;   

    	}

  	
    	public Button(Rectangle rectangle, OnClick onClick, string texHover, 
                  	string texPressed, string texNormal, IntPtr textFont)
    	{
        	buttonPos.X = rectangle.X;
        	buttonPos.Y = rectangle.Y;   
        	base.zOrder = 0;
        	this.areaRectangle = rectangle;
        	this.onClick = onClick;
        	this.texNormalS = texNormal;
        	this.texPressedS = texPressed;
        	this.textHoverS = texHover; 
        	this.textFont = textFont;
        	this.fontColor = Color.White;   
    	}

    	public bool Discard()
    	{
        	return base.discard; 
    	}

    	public int ZOrder()
    	{
        	return zOrder;
    	}

    	public Vector2 GetPos()
    	{
        	return buttonPos; 
    	}

    	public void SetPos(Vector2  vect)
    	{
        	buttonPos = vect; 
        	areaRectangle.X = vect.X;
        	areaRectangle.Y = vect.Y;  
        	textPosition = new Vector2(areaRectangle.X + (areaRectangle.Width - textWidth) / 2,
                                    	areaRectangle.Y + ((areaRectangle.Height - 15) / 2) + 14);
    	}

    	public Rectangle GetRectangle()
    	{
        	return areaRectangle; 
    	}

    	public string AccesibleName()
    	{
        	return accesibleName;
    	}

    	public void Create()
    	{
        	textHover = ContentManager.GetTextureByName(textHoverS);
        	texPressed = ContentManager.GetTextureByName(texPressedS);
        	texNormal = ContentManager.GetTextureByName(texNormalS);
        	texCurrent = texNormal; 
    	}

    	public void Update(Cursor cursor)
    	{
        	if (areaRectangle.Contains(cursor.Position))
        	{
            	texCurrent = textHover;
            	if (cursor.State == Glut.GLUT_DOWN)
            	{
                	isPressed = true;
                	texCurrent = texPressed;
            	}
            	else

                	if (isPressed)
                	{
                    	if (cursor.State == Glut.GLUT_UP)
                    	{
                        	isPressed = false;
                        	texCurrent = texNormal;
                        	if (onClick != null)
                        	{
                            	AudioPlayback.PlayOne("click.wav");  
                            	base.onClick.Invoke();
                        	} 
                    	}
                	}
        	}
        	else
        	{
            	isPressed = false;
            	texCurrent = texNormal;
        	}
    	}

    	public void Draw()
    	{
        	Sprite.DrawSprite(areaRectangle, texCurrent);
        	Sprite.DrawText(textPosition.X, textPosition.Y, text, textFont, fontColor);  
    	}
	}
}




#16 H3g3m0n   Members   -  Reputation: 122

Like
0Likes
Like

Posted 24 September 2011 - 03:15 AM

Another possibility is to look at embedding webkit. Then you can write a HTML5 UI, similar to how many commercial games use flash. You also get some neat feature like vector graphics, canvas2D and maybe even video (wouldn't it be great if games allowed you to pause and rewind videos). Since you have a full HTML5 renderer you can get more of game themed UI. It might add a bit of overhead though.

I did something like that with QT's QWebView. Unfortunately the webkit build in QT is currently missing some graphical features like shadows, blur and so on.

Otherwise QT itself can be overlayed over a OpenGL context (also it's possible for the QT widgets to be rendered in a 2D scene). There's some official demo code for that:
http://labs.qt.nokia.com/2008/06/27/accelerate-your-widgets-with-opengl/
http://labs.qt.nokia.com/2008/12/02/widgets-enter-the-third-dimension-wolfenqt/
http://labs.qt.nokia.com/2006/10/27/gloverlay/

Only problem is that QT by default won't exactly look very gameish, but it's great for editing tools or technical stuff.

There's Awesomium (a webkkit binding lib aimed at games, used in Eve online) which has sadly gone commercial (although if you look around you can find an older GPL'd fork) and there's also Berkelium which uses Chromium rather than webket direct, unfortunately it's a massive pain to build/develop since you need to compile all of Chromium rather than just using libwebkit.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS