2d opengl?

BlitzMax Forums/BlitzMax Beginners Area/2d opengl?

Eric Vaughn(Posted 2006) [#1]
Hi,

I'm trying to toy around with OpenGL at the moment. I'm making a 2d game and I was wondering if it could help in any way. I won't be having any 3d elements in my game.

Am I wasting my time? I heard by word of mouth that OpenGL can speed up your game a lot.

Thanks.


Gabriel(Posted 2006) [#2]
Am I wasting my time?

Not wasting your time exactly, but judging by your thread last night where you said you were just starting with BlitzMax and not finding it easy, I'd say you're getting ahead of yourself. I highly recommend sticking with the official BlitzMax language and modules until you're much more confident with those.

I heard by word of mouth that OpenGL can speed up your game a lot.

You heard wrong if this was about BlitzMax. BlitzMax has an OpenGL driver and a DX7 driver built in. That's not to say that an experienced programmer couldn't do it better than Max2D does it, but Max2D already uses OpenGL if you want it to. You can use whichever you prefer ( unless you're on Mac or Linux in which case, there's no way to use anything *but* OpenGL. )

Look up SetGraphicsDriver in the documentation. Note that if you're on Windows, BMax will default to DirectX7, and you will need to set the graphics driver to OpenGL if that's what you want.


Dubious Drewski(Posted 2006) [#3]
Type this at the top of your program:
SetGraphicsDriver GLMax2DDriver()

That should do it. BlitzMax defaults to DirectX, but that
line changes it to OpenGl. Program like normal after that.
I wouldn't worry about the more advanced OpenGL usage
just yet. Just keep practicing making programs for now.

Why? Because this:
	If TextureImage <> Null											
		glGenTextures(1, Varptr texture)					
		glBindTexture(GL_TEXTURE_2D, texture)
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage.width, TextureImage.height, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage.pixels)
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
	EndIf
is what OpenGL looks like. I'm sure you wouldn't want to touch that just yet.


Eric Vaughn(Posted 2006) [#4]
SetGraphicsDriver GLMax2DDriver()

Graphics 640, 480, 32, 60

HideMouse

While Not KeyHit( KEY_ESCAPE )

Cls

DrawText "Test!",0,0

Flip

Wend

ShowMouse


-----


This is 2d OpenGL? Will it work essentially the same on Linux and Macs?


Eric Vaughn(Posted 2006) [#5]
btw how do I make a code box for the forums?


tonyg(Posted 2006) [#6]
Yes
FAQ


Boulderdash(Posted 2006) [#7]
This is your code changed multiplatform compliant.




Eric Vaughn(Posted 2006) [#8]
SetGraphicsDriver BufferedD3D7Max2DDriver()


Is this still OpenGL mode or something else?


Gabriel(Posted 2006) [#9]
That's DirectX D3D7. I'm not sure why Gav posted that, since you clearly indicated you wanted OpenGL, so there is no need for his code in order for your code to be cross platform.


Cruis.In(Posted 2006) [#10]
opengl is cross platform itself, just use it instead of d3d, and it wont matter what any one is using, because as you can see he only specified d3d for win32... and opengl works with win32 as well, so by always using opengl, you win.


Gabriel(Posted 2006) [#11]
so by always using opengl, you win.

No, you don't. A considerably smaller portion of people have usable OpenGL drivers on Windows than have usable D3D drivers. So if you're making casual games where you're appealing to people who don't play hardcore games, you lose if you always use OpenGL.

In this specific instance, because Eric *wants* to use OpenGL ( and I'm not going to question his reasons, that's his choice ) then he should just use OpenGL on all platforms. But it's not a general solution for everyone. It's a balance which has to be weighed up by each individual when they come to make this choice.


xlsior(Posted 2006) [#12]
No, you don't. A considerably smaller portion of people have usable OpenGL drivers on Windows than have usable D3D drivers. So if you're making casual games where you're appealing to people who don't play hardcore games, you lose if you always use OpenGL.


Which is exactly why DirectX was added to Blitzmax in the first place -- the original launch was OpenGL only, and it took a lot of complaints about speed issues on windows to convince BRL to add DirectX as well... But it was fairly clear that that was never the original intent.


Gabriel(Posted 2006) [#13]
Absolutely. I don't remember specifically, but I was probably one of the complaining people.


bradford6(Posted 2006) [#14]
Eric,

I think the main point you should understand is this. Max2D uses the onboard graphics card to create 2D images using 3D hardware and features. the following commands make it easy:

SetColor
SetHandle
SetScale
SetRotation
SetOrigin
SetViewPort
SetBlend
SetAlpha


when you create a graphics mode (whether it is Direct3D or OpenGL) you are using the PC's hardware accelerator to do the drawing.

right now, Mac and linux default to OpenGL and windows defaults to D3D so if you leave that part alone, you'll be fine.

graphics 800,600


is all you need.


Cruis.In(Posted 2006) [#15]
i thought everyone got better frames with opengl on windows and than the directx driver. especially since its only d3d7


Gabriel(Posted 2006) [#16]
They probably do get better frame rates, at least those that can actually run it. Looking at various statistics from various casual game developers, you can expect anything from about 10% to about 40% of people not to be able to run the game at all if it's OpenGL on Windows, which is significantly higher than D3D7.


Eric Vaughn(Posted 2006) [#17]
I'm probably going to have a lot of sprites on screen at once in my game. They are going to be simple pixel art images that don't need antialiasing or anything like that.

For maximum speed with a large amount of sprites on screen, should I go for Direct 3D or OpenGL (on the PC)?


tonyg(Posted 2006) [#18]
Is there any other reason why you'd want to use DX or OpenGL? If not, then write your game and check the speed in DX. Even better write a demo with the number of sprites you're expecting and see what happens. If it's too slow try the OGL driver as it's a single command to add.
On the other hand you might want to use the DX9 driver which is out there somewhere and/or IndiePath's single surface TAnim module.


LarsG(Posted 2006) [#19]
Never mind the speed differences of OGL and DX yet.. just get to coding your game..
Later on, you can test it by changing the graphicsdrivers..
And even better yet, let the user be able to choose if he wants to go OGL or DX..

my 2 cents


ImaginaryHuman(Posted 2006) [#20]
Unless you want to code direct OpenGL yourself in which case you can't just switch that on and off with the graphics driver without having to recode everything.


LarsG(Posted 2006) [#21]
well, yeah, but then you're not very likely to be uncertain if you're gonna do OGL or DX..


Eric Vaughn(Posted 2006) [#22]
Ok, I've been coding for a few weeks now and I think I've gotten a pretty good hold of basic BlitzMax coding.

Right now, what I want to do is take a 2D image and scale it down to about 2/3 of it's actual size.

Any advice on how to do that?


tonyg(Posted 2006) [#23]
Setscale?


Who was John Galt?(Posted 2006) [#24]
Yeah what tony said.

The best advice I can give you is forget about D3D and OpenGL specifics at this stage. Max handles it all for you. When you've got a working game, you can easily add some code at the end to ensure the optimal driver (D3D or OGL) is used.