Texture

Discuss OpenGL® programming with the GL Galore plugin here
Post Reply
User avatar
lazi
Posts: 295
Joined: Fri Feb 25, 2011 12:08 am

Texture

Post by lazi » Wed Sep 20, 2017 10:24 pm

I would like to draw a simple textured rectangle.
Read some c examples, guides but failed. OpenGL is a really nasty beast...

Does somebody has a simple working Gl Galore texturing example?
If nobody done it yet, I will post where I lost, and hope to fix it together.

User avatar
lazi
Posts: 295
Joined: Fri Feb 25, 2011 12:08 am

Re: Texture

Post by lazi » Wed Sep 20, 2017 11:13 pm

Hehe, I made it and at last it is working!!
Nice to use that damn modern video hardware. :)

Here is the source if somebody interested:

Code: Select all

/*
** textured rotated rectangle
*/
@REQUIRE "glgalore"

/*
** Define four displays
*/
@DISPLAY {Sizeable = True, Title = "texture"}

;@BRUSH 1,"rotatebitmap.jpg"
@BRUSH 1,"hollywood:Examples/Hollywood/3DCube/03.jpg"
ScaleBrush(1,256,256)

Function p_DrawGL()

    gl.ClearColor( 0, 0, 0, 0 )
	gl.Clear( #GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT )

	gl.MatrixMode( #GL_PROJECTION )
	gl.LoadIdentity()
	;gl.Ortho( -2, 2, -2, 2, -1, 1 )

	gl.MatrixMode( #GL_MODELVIEW )
	gl.LoadIdentity()

	gl.Color( 1, 1, 1 )

	gl.BindTexture( #GL_TEXTURE_2D, texid[ 0 ] )


 	;gl.Translate(0, 0, -10)
	;gl.Rotate(r, 0, 1, 0)
	;gl.Rotate(r, 1, 1, 1)
	gl.rotate(r,0,0,1)
  
  	gl.Begin(#GL_QUADS)

	gl.TexCoord( 0, 0 )
	gl.Vertex( 1,  1, 1)
	gl.TexCoord( 1, 0 )
	gl.Vertex(-1,  1, 1)
	gl.TexCoord( 1, 1 )
	gl.Vertex(-1, -1, 1)
	gl.TexCoord( 0, 1 )
	gl.Vertex( 1, -1, 1)
  	gl.End()


	r = r + 0.1

EndFunction

/* new window size */ 
Function p_Reshape(msg)

	; initialize GL context	
	gl.ClearColor(0, 0, 0, 0)
	gl.Enable(#GL_TEXTURE_2D)

	gl.MatrixMode(#GL_PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(20, msg.width / msg.height, 5, 15)	
	gl.Viewport(0, 0, msg.width, msg.height)

	gl.MatrixMode(#GL_MODELVIEW)
	;gl.MatrixMode(#GL_TEXTURE)

EndFunction

;init
gl.Enable( #GL_TEXTURE_2D )
texid=gl.GenTextures( 1 )
gl.BindTexture( #GL_TEXTURE_2D, texid[ 0 ] )
	
gl.TexImagefrombrush(0, 1 )
	
gl.TexParameter( #GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_NEAREST )
gl.TexParameter( #GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_NEAREST )

p_Reshape({Width = 640, Height = 640})

InstallEventHandler({
	SizeWindow = Function(msg) p_Reshape(msg) EndFunction,
	ModeSwitch = Function(msg) p_Reshape(msg) EndFunction})
	 
; start hardware double-buffering for window
BeginDoubleBuffer(True)

EscapeQuit(True)

; main loop
Repeat
	
	; draw next cube frame
	p_DrawGL()
		
	; flip buffer into view
	Flip

	CheckEvent
Forever	                                             

User avatar
Allanon
Posts: 439
Joined: Sun Feb 14, 2010 8:53 pm
Location: Italy
Contact:

Re: Texture

Post by Allanon » Fri Sep 29, 2017 8:49 am

Hi Lazi,
I've coded a nice engine with a sprite system and particle system using OpenGL and GLGalore, it also uses DisplayLists to speed up rendering, it can handle parallax effects, load sprite sheets, animated sprites and many other game-oriented features.

See here and here to have an idea, there are no docs so far but the soruce code is fully commented with each parameter description.

If you are interested I can send you the source code, it's not yet 100% complete but you can get some ideas or use it as is using my demos as base.
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

User avatar
lazi
Posts: 295
Joined: Fri Feb 25, 2011 12:08 am

Re: Texture

Post by lazi » Sun Oct 08, 2017 11:04 pm

Thanks Allanon!

I am interested in your engine as I am just in the beginning of the road toward OpenGL expertise :)
Your projects are quite professional. It would be a pleasure to see some well done sources.

User avatar
Allanon
Posts: 439
Joined: Sun Feb 14, 2010 8:53 pm
Location: Italy
Contact:

Re: Texture

Post by Allanon » Thu Nov 02, 2017 8:51 am

Hi Lazi,
sorry for the late answer, I missed completely your reply!

Please send me your email with a PM so I can send you the current sources :)
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

Post Reply