May 31, 2020, 08:43:03 PM

Author Topic: Plotting x and y in AGK Studio  (Read 675 times)

Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1023
Plotting x and y in AGK Studio
« on: January 05, 2020, 10:55:54 AM »
I just purchased AGK2 and have been attempting to plot in X and Y, within a simple 2D interface.

I've tried the AGK forums - however I suspect my attempts at using the forum's codebox for AGK is clobbering my posts/submissions, hopefully someone on these forums can help.

I'm trying to call a copy of the plot function (plot2) to display a second pixel racing horizontally across the GUI. All attempts at plotting my 3rd object have failed. I appreciate I could just use the existing function - however this would not help with my understanding of how AGK syntax is constructed.

Most of the Heightmap examples on the forums are in DarkBasic - which isn't much help with AGK Studio ;)

My goal is to create a heightmap in code, with a view to copying this, saving the image and then loading into a 3d View.

I'm having a little trouble with the first step.....



Code: [Select]

// Probe testing

// show all errors
SetErrorMode(2)

// Window size
local sizex# = 800
local sizey# = 800

// Initielise the window
gosub _init

// Load the shader
LoadFullScreenShader(1, "s_plot.ps")
LoadFullScreenShader(2, "s_show.ps")

LoadFullScreenShader(3, "s_show.ps")

// create the rendertextures
CreateRenderImage( 1, sizex#, sizey#, 0, 0 )
CreateRenderImage( 2, sizex#, sizey#, 0, 0 )

// CreateRenderImage( 3, sizex#, sizey#, 0, 0 ) // is this necessary ?
                                                // suspect can just render to image 2?

SetImageMagFilter( 1, 0 )
SetImageMinFilter( 1, 0 )
SetImageMagFilter( 2, 0 )
SetImageMinFilter( 2, 0 )

SetImageMagFilter( 3, 0 )
SetImageMinFilter( 3, 0 )


SetShaderConstantByName(1, "size", sizex#, sizey#, 0, 0)

SetShaderConstantByName(3, "size", sizex#, sizey#, 0, 0)  // will this resolve bot plotting
                                                          // to screen ?

// create drawing helpers
CreateObjectQuad(1)
SetObjectImage(1, 1, 0)
SetObjectShader(1, 1)

CreateObjectQuad(2)
SetObjectImage(2, 2, 0)
SetObjectShader(2, 2)

// create additional plotting object - Hmm, I'm missing something
CreateObjectQuad(3)
SetObjectImage(3, 3, 0)
SetObjectShader(3, 3)

SetCameraPosition( 1, 0.0, 0.0, -2.5 )
SetCameraLookAt( 1, 0.0, 0.0, 0.0, 0 )

local sn# = 0.0
local rr# = 0.0
local gg# = 0.0
local bb# = 0.0

local xx# = 100
local yy# = 100

local slowdown=1

do
loco = ScreenFPS()

sn# = sn# + 0.01

// draw a colorful Lissajous curve
rr# = rr# + 0.01
if rr# >= 256 then rr# = rr# - 256.0
gg# = gg# + 0.022
if gg# >= 256 then gg# = gg# - 256.0
bb# = bb# + 0.38
if bb# >= 256 then bb# = bb# - 256.0
plot(floor(sin(sn#*1.2)*sizex#*0.45+sizex#*0.5), floor(cos(sn#)*sizey#*0.45+sizey#*0.5), rr#, gg#, bb#)

// move a red pixel across the screen

plot2(xx#,yy#,250,1,1)

slowdown=slowdown+1

if slowdown>100

if xx#<100
xx#=xx#+1
else
xx#=1
endif

slowdown=0

endif


if (GetRawKeyPressed( 27 ))
end
endif

SetRenderToImage( 1, -1)
DrawObject( 2 )           // Why is object 2 just up here
                          // And not after RenderToScreen ?

SetRenderToImage( 2, -1)
DrawObject( 1 )



// attempt at adding pixel (Object 3) marching to the right 100 pixels down

SetRenderToScreen()
// screen text
Print( "FPS: " + str(loco,2) )

Print( "xx: " + str(xx#,2) + "yy: " + str(yy#,2) )

// DrawObject( 3 )
DrawObject( 1 )
// DrawObject( 3 )
Render2DFront()

//DrawObject( 3 )
//Render2DFront()


Swap()
//sync()
loop

function plot(x, y, r, g, b)
SetShaderConstantByName(1, "pos", x, y, 0, 0)
SetShaderConstantByName(1, "color", r, g, b, 0)
endfunction

function plot2(x, y, r, g, b)
SetShaderConstantByName(3, "pos", x, y, 0, 0)
SetShaderConstantByName(3, "color", r, g, b, 0)
endfunction

_init:
// set window properties
SetAntialiasMode( 0 )
SetWindowTitle( "Plotter" )
SetWindowSize( sizex#, sizey#, 0 )
SetWindowAllowResize( 0 )
SetScissor( 0,0,0,0 )
setcamerarange(1, 0.05, 25)
SetGenerateMipmaps( 0 )

// set display properties
//SetVirtualResolution( 800, 800 )
//SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetClearColor( 0,0,0 )
return





I can call my red line plotter using the original 'plot' (by calling plot(x,y,...) instead of plot2(x,y,....) function - however - this obliterates the original colourful curve - which I suspected.


Offline blinkok

  • Full Member
  • ***
  • Posts: 170
Re: Plotting x and y in AGK Studio
« Reply #1 on: January 05, 2020, 11:20:48 PM »
Without the shaders (s_plot.ps, s_show.ps) it's difficult to see whats going on

Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1023
Re: Plotting x and y in AGK Studio
« Reply #2 on: January 06, 2020, 05:19:49 PM »
had another go at trying to get the red line AND the lissajous multicoloured line rendering at the same time - can only manage one or the other so far....

Code: [Select]

// Probe testing

//Edited on 6 Jan 2020

// show all errors
SetErrorMode(2)

// Window size
local sizex# = 800
local sizey# = 800

// Initielise the window
gosub _init

// Load the shader
LoadFullScreenShader(1, "s_plot.ps")
LoadFullScreenShader(2, "s_show.ps")

LoadFullScreenShader(3, "s_show.ps")

// create the rendertextures
CreateRenderImage( 1, sizex#, sizey#, 0, 0 )
CreateRenderImage( 2, sizex#, sizey#, 0, 0 )

CreateRenderImage( 3, sizex#, sizey#, 0, 0 ) // is this necessary ?
                                                // suspect can just render to image 2?

SetImageMagFilter( 1, 0 )
SetImageMinFilter( 1, 0 )
SetImageMagFilter( 2, 0 )
SetImageMinFilter( 2, 0 )

SetImageMagFilter( 3, 0 )
SetImageMinFilter( 3, 0 )


SetShaderConstantByName(1, "size", sizex#, sizey#, 0, 0)

SetShaderConstantByName(3, "size", sizex#, sizey#, 0, 0)  // will this resolve not plotting
                                                          // to screen ?

// create drawing helpers
CreateObjectQuad(1)
SetObjectImage(1, 1, 0)
SetObjectShader(1, 1)

CreateObjectQuad(2)
SetObjectImage(2, 2, 0)
SetObjectShader(2, 2)

// create additional plotting object - Hmm, I'm missing something - or is this becoming the default
// drawing target ?
CreateObjectQuad(3)
SetObjectImage(3, 3, 0)
SetObjectShader(3, 3)

SetCameraPosition( 1, 0.0, 0.0, -2.5 )
SetCameraLookAt( 1, 0.0, 0.0, 0.0, 0 )

local sn# = 0.0
local rr# = 0.0
local gg# = 0.0
local bb# = 0.0

local xx# = 100
local yy# = 100

local slowdown=1

do
loco = ScreenFPS()

sn# = sn# + 0.01

// draw a colorful Lissajous curve
rr# = rr# + 0.01
if rr# >= 256 then rr# = rr# - 256.0
gg# = gg# + 0.022
if gg# >= 256 then gg# = gg# - 256.0
bb# = bb# + 0.38
if bb# >= 256 then bb# = bb# - 256.0
//plot(floor(sin(sn#*1.2)*sizex#*0.45+sizex#*0.5), floor(cos(sn#)*sizey#*0.45+sizey#*0.5), rr#, gg#, bb#)

// move a red pixel across the screen

plot2(xx#,yy#,250,1,1)

slowdown=slowdown+1

if slowdown>100

if xx#<100
xx#=xx#+1
else
xx#=1
yy#=yy#+40
endif

slowdown=0

endif


if (GetRawKeyPressed( 27 ))
end
endif

SetRenderToImage( 1, -1)
DrawObject( 2 )           // Why is object 2 just up here
                          // And not after RenderToScreen ?

SetRenderToImage( 2, -1)
DrawObject( 1 )



// attempt at adding pixel (Object 3) marching to the right 100 pixels down

SetRenderToScreen()
// screen text
Print( "FPS: " + str(loco,2) )

Print( "xx: " + str(xx#,2) + "yy: " + str(yy#,2) )

DrawObject( 3 )           // This simply fails when uncommented
DrawObject( 1 )           // Uncommenting this line allows for red line to be drawn
                       // OR for the multi-coloured line to be drawn - dependent upon
                       // whether line 81 or 85 is commented out.....

Render2DFront()

//DrawObject( 3 )
//Render2DFront()


Swap()
//sync()
loop

function plot(x, y, r, g, b)
SetShaderConstantByName(1, "pos", x, y, 0, 0)
SetShaderConstantByName(1, "color", r, g, b, 0)
endfunction

// edited object 3 to object 1.....

function plot2(x, y, r, g, b)
SetShaderConstantByName(1, "pos", x, y, 0, 0)       //
SetShaderConstantByName(1, "color", r, g, b, 0)

//SetShaderConstantByName(3, "pos", x, y, 0, 0)     // trying 3 in here....
//SetShaderConstantByName(3, "color", r, g, b, 0)   // 3 fails - suggesting something is not set up propelry.

endfunction

_init:
// set window properties
SetAntialiasMode( 0 )
SetWindowTitle( "Plotter" )
SetWindowSize( sizex#, sizey#, 0 )
SetWindowAllowResize( 0 )
SetScissor( 0,0,0,0 )
setcamerarange(1, 0.05, 25)
SetGenerateMipmaps( 0 )

// set display properties
//SetVirtualResolution( 800, 800 )
//SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetClearColor( 0,0,0 )
return



Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1023
Re: Plotting x and y in AGK Studio
« Reply #3 on: January 06, 2020, 06:45:11 PM »
this is a start at creating greyscale lines..... for heightmap production.

Code: [Select]

// Probe testing

// Credit to original code provided by the following:

// Bengismo
// https://forum.thegamecreators.com/thread/221459




//Edited on 6 Jan 2020

// show all errors
SetErrorMode(2)

// Window size
local sizex# = 800
local sizey# = 800

// Initielise the window
gosub _init

// Load the shader
LoadFullScreenShader(1, "s_plot.ps")
LoadFullScreenShader(2, "s_show.ps")

LoadFullScreenShader(3, "s_show.ps")

// create the rendertextures
CreateRenderImage( 1, sizex#, sizey#, 0, 0 )
CreateRenderImage( 2, sizex#, sizey#, 0, 0 )

CreateRenderImage( 3, sizex#, sizey#, 0, 0 ) // is this necessary ?
                                                // suspect can just render to image 2?

SetImageMagFilter( 1, 0 )
SetImageMinFilter( 1, 0 )
SetImageMagFilter( 2, 0 )
SetImageMinFilter( 2, 0 )

SetImageMagFilter( 3, 0 )
SetImageMinFilter( 3, 0 )


SetShaderConstantByName(1, "size", sizex#, sizey#, 0, 0)

SetShaderConstantByName(3, "size", sizex#, sizey#, 0, 0)  // will this resolve not plotting
                                                          // to screen ?

// create drawing helpers
CreateObjectQuad(1)
SetObjectImage(1, 1, 0)
SetObjectShader(1, 1)

CreateObjectQuad(2)
SetObjectImage(2, 2, 0)
SetObjectShader(2, 2)

// create additional plotting object - Hmm, I'm missing something - or is this becoming the default
// drawing target ?
CreateObjectQuad(3)
SetObjectImage(3, 3, 0)
SetObjectShader(3, 3)

SetCameraPosition( 1, 0.0, 0.0, -2.5 )
SetCameraLookAt( 1, 0.0, 0.0, 0.0, 0 )

local sn# = 0.0
local rr# = 0.0
local gg# = 0.0
local bb# = 0.0

local xx# = 100
local yy# = 100

local slowdown=1

local gscale=255

do
loco = ScreenFPS()

sn# = sn# + 0.01

// draw a colorful Lissajous curve
rr# = rr# + 0.01
if rr# >= 256 then rr# = rr# - 256.0
gg# = gg# + 0.022
if gg# >= 256 then gg# = gg# - 256.0
bb# = bb# + 0.38
if bb# >= 256 then bb# = bb# - 256.0
//plot(floor(sin(sn#*1.2)*sizex#*0.45+sizex#*0.5), floor(cos(sn#)*sizey#*0.45+sizey#*0.5), rr#, gg#, bb#)

// move a red pixel across the screen

//plot2(xx#,yy#,gscale,gscale,gscale)    // vain attempt at plotting 5 horizontal lines adjacent too each other
//plot2(xx#,yy#+1,gscale,gscale,gscale)
plot2(xx#,yy#+2,gscale,gscale,gscale)
//plot2(xx#,yy#+3,gscale,gscale,gscale)
//plot2(xx#,yy#+4,gscale,gscale,gscale)

//plot2(xx#,yy#,250,1,1)

slowdown=slowdown+1

if slowdown>100

if xx#<100
xx#=xx#+1
else
xx#=1
yy#=yy#+40
endif

slowdown=0

gscale=gscale-1

if gscale<2

gscale=255

endif


endif


if (GetRawKeyPressed( 27 ))
end
endif

SetRenderToImage( 1, -1)
DrawObject( 2 )           // Why is object 2 just up here
                          // And not after RenderToScreen ?

SetRenderToImage( 2, -1)
DrawObject( 1 )



// attempt at adding pixel (Object 3) marching to the right 100 pixels down

SetRenderToScreen()
// screen text
Print( "FPS: " + str(loco,2) )

Print( "xx: " + str(xx#,2) + "yy: " + str(yy#,2) + " gscale: " + str(gscale,2) )

DrawObject( 3 )           // This simply fails when uncommented
DrawObject( 1 )           // Uncommenting this line allows for red line to be drawn
                       // OR for the multi-coloured line to be drawn - dependent upon
                       // whether line 81 or 85 is commented out.....

Render2DFront()

//DrawObject( 3 )
//Render2DFront()


Swap()
//sync()
loop

function plot(x, y, r, g, b)
SetShaderConstantByName(1, "pos", x, y, 0, 0)
SetShaderConstantByName(1, "color", r, g, b, 0)
endfunction

// edited object 3 to object 1.....

function plot2(x, y, r, g, b)
SetShaderConstantByName(1, "pos", x, y, 0, 0)       //
SetShaderConstantByName(1, "color", r, g, b, 0)

//SetShaderConstantByName(3, "pos", x, y, 0, 0)     // trying 3 in here....
//SetShaderConstantByName(3, "color", r, g, b, 0)   // 3 fails - suggesting something is not set up propelry.

endfunction

_init:
// set window properties
SetAntialiasMode( 0 )
SetWindowTitle( "Grayscale Plotter" )
SetWindowSize( sizex#, sizey#, 0 )
SetWindowAllowResize( 0 )
SetScissor( 0,0,0,0 )
setcamerarange(1, 0.05, 25)
SetGenerateMipmaps( 0 )

// set display properties
//SetVirtualResolution( 800, 800 )
//SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetClearColor( 0,0,0 )
return




Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1023
Re: Plotting x and y in AGK Studio
« Reply #4 on: January 09, 2020, 04:51:11 AM »
Quite pleased with these results - +1 vote for AGK here.

I've been wondering how to achieve creating a scene in code (using lats, longs and altitiude from a GPS device) - I'm a step closer this morning ;)


Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1023
Re: Plotting x and y in AGK Studio
« Reply #5 on: January 25, 2020, 03:44:48 AM »
A little more progress - need to work on the smoothing algorithm - looks like the road to Mordor at the moment  :)

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal