SimpleGL


What is SimpleGL?

SimpleGL is a MATLAB mex file for MacOS which allows you to do simple 2D things with OpenGL such as create textures from windows and rotate them arbitrarily. The idea is to 1) take advantage of all the 16MB+ OpenGL accelerators that have come standard with all new Macs since the Blue and White G3, and 2) to make a cross-platform set of vision research tools (even though it is Mac specific for now, it could be easily adapted). Another bonus: the ATI Rage 128 and Radeon drivers support page flipping (and/or blit between front and back buffers really, really fast), so you can get tear-free fullscreen animations.

The following help is given when you type "SimpleGL" at the MATLAB prompt:

glContextID = SimpleGL('OpenContext', windowPtr, [bgrColor])

	Opens an OpenGL context using the window pointed to by windowPtr
	using background color bgrColor, a 1x3 matrix (if omitted, [0 0 0] assumed)
	Returns an identifier for the context.
	IMPORTANT: The window must be in 32 bits per pixel
	("millions of colors") mode!
	VBLSync for the context is ON by default. See 'VBLSync'
	If glContextID is 0, no context could be created.

ok = SimpleGL('ContextBgr', glContextID, bgrColor)

	Sets the given context's background color to the value of'bgrColor',
	a 1x3 [R G B] matrix where elements can range from 0 to 255.
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

ok = SimpleGL('MaskingRect', glContextID, [r])

	Sets the given context's viewport to Rect r in [L T R B] order.
	If the rectangle is not specified, the whole context
	becomes the viewport.
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

glTextureID = SimpleGL('MakeTexture', windowPtr, [r], [glTexture])

	Converts the contents of the window (or Rect r [L T R B] in that window)
	into an OpenGL texture, and returns an identifier for the texture.
	If an existing glTexture id is supplied, you will create a new texture
	that will overwrite it,starting in the upper left hand corner.
	(neither of the new texture's dimensions can be larger than the original).
	IMPORTANT: The width and height of the window (or Rect) must be powers of 2,
	unless you are overwriting an existing texture. In that case, the existing texture
	must have been created in a previous MakeTexture command with power of two dimensions.
	To be drawn in an OpenGL context, bind it to a rect (see 'TextureRect').
	If glTextureID is 0, no texture could be made.

glRectID = SimpleGL('MakeRect', glContext, [r], [glTexture or rectColor], [degrees])

	Makes a rectangle in the context specified with Rect r coordinates [L T R B],
	(if not specified, will be the size of the entire context window), with the texture
	specified by a glTexture or color specified by 1x3 RGB rectColor ([0 0 0] default), and
	with the orientation specified by degrees (if not specified, there's no rotation.)
	The rectangle is set to active (see 'ActiveRect').
	If glRectID is 0, no rectangle could be made.

ok = SimpleGL('CornerRect', glRectID, [r])

	Sets new coordinates for an existing rectangle in [L T R B] order as
	specified by the Rect r (in original context window's coordinates).
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

ok = SimpleGL('TextureRect', glRectID, glTextureID, [xCycles], [yCycles])

	Textures an existing rectangle with an existing texture
	specified by the glTextureID. Scales texture by xCycles,
	yCycles (if specified) to produce the number of cycles across the rect.
	If not specified, the default for both xCycles and yCycles is 1.0
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

ok = SimpleGL('TranslateRectTexture', glRectID, xTrans, yTrans)

	Translates the texture on rect glRectID by xTrans, yTrans
	The units should be in the -1 .. 1 range, where a translation
	of 1 or -1 will translate the texture its full width (or height)
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

ok = SimpleGL('ColorRect', glRectID, rectColor)

	Sets the given rect's color to the value of 'rectColor',
	a 1x3 [R G B] matrix where elements can range from 0 to 255.
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

ok = SimpleGL('OrientRect', glRectID, degrees)

	Orients an existing rectangle with the new orientation
	specified by degrees.
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

ok = SimpleGL('ActiveRect', glRectID, active)

	Sets the given rect's active state to the value of'active'.
	If active is 1, the rect will be drawn on the next call to
	DrawContext. If active is 0, it won't.
	If ok is 0, the request failed.

ok = SimpleGL('DrawContext', glContextID)

	Draws the context specified by glContextID.
	If ok is 0, the request failed.

ok = SimpleGL('VBLSync', glContextID, vsync)

	Sets the given context's VBLSync flag to the value of 'vsync',
	which can be 1 (sync) or 0 (don't sync).
	Synching to VBL will cause OpenGL to wait for the display to enter
	its vertical blanking interval between frames before swapping its internal
	buffers to update the display. Slows performance but reduces tears to at most 1.
	Takes effect on next call to DrawContext.
	If ok is 0, the request failed.

ok = SimpleGL('CloseContext', glContextID)

	Closes the context specified by glContextID.
	If ok is 0, the request failed.

How do I get it?

SimpleGL-12-18-00.sit.hqx [384k] (includes source -- you'll need the OpenGL SDK from Apple)

Who uses it?

Mike Weliky is using it to display full-screen drifting gratings with no tearing and at arbitrary orientations. That's primarily what I developed it for, but I'd like to extend it to take more advantages of OpenGL like transparency and layering in the depth buffer.
Up
Last updated 10/2001
bdsinger@princeton.edu