Author Topic: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2  (Read 3283 times)

0 Members and 1 Guest are viewing this topic.

kryton9

  • Guest
GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« on: August 05, 2012, 01:41:06 AM »
How would I write this in oxygen, it is a mutli-dimensional array?
GLubyte MatrixImage[ImageHeight][ImageWidth][3];

Thanks, my brain is dead at 5:40am. Drawing a blank :)

Charles Pegge

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #1 on: August 05, 2012, 04:10:21 AM »
Hi Kent,
for a static array:

%ImageHeight 480
%ImageWidth 480
%ColorWidth 3

GLubyte MatrixImage[ImageHeight*ImageWidth*ColorWidth]


macro mi(h,w,b) {MatrixImage[((h*ImageWidth)+w)*ColorWidth+b]}

mi(0,1,2)=mi(1,1,2) 'etc


Charles

Peter

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #2 on: August 05, 2012, 05:17:05 AM »
My version:

'byte MatrixImage[ImageHeight][ImageWidth][3]
Code: [Select]
include "win64.inc"


%ImageHeight=240
%ImageWidth =320
%ImageZ     =3
%Value = ImageHeight*ImageWidth*ImageZ

byte MatrixImage[value]

byte huhu   
sys h,w,z

For x=0 to value
    MatrixImage[x] = Rand(1,255)
Next

Randomize
h= Rand(0,239): w= Rand(0,319): z= Rand(0,2)
huhu= MatrixImage[(h*w+w)*z]
print "Okay  " + huhu

Peter

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #3 on: August 05, 2012, 06:24:22 AM »
Hi Charles,

runs this with you?
Code: [Select]
! MessageBeep Lib "user32.dll" (sys wType) As Long
! MessageBox  Lib "user32.dll" Alias "MessageBoxA" (sys hwnd, string lpText, lpCaption, sys wType) As Long

macro m2m(m1, m2)  'this is for asm only
    push m2
    pop  m1
end macro

bstring caption = "City Herne"
bstring text = "click away!"

messagebox 0,text,caption,48
messagebeep 0

type FIELD
    sys  a
    sys  b
end type

FIELD koor
sys  zm=100

m2m ( koor.a, &zm)
m2m ( koor.b, zm)

print koor.a
print koor.b

kryton9

  • Guest
C source finds errors in header in glo folder
« Reply #4 on: August 05, 2012, 11:01:26 AM »
Thanks guys, I tried the mulitplication into a single array, but then got messed up with the assignments to the array the color info.

So I got up today and am trying to make the c version run straight out of oxygen. I am using C.inc by Charles and get some errors in the gl.h and one more header, forgot which now.
Anyways, you will get the same errors, so perhaps a good way to check the headers this way, doing c tests.

Here is the C source in Oxygen that I was trying to convert, but it should run without conversion with c.inc correct?

Files included:
c.inc this is straight copy from C:\Code\OxygenBasic\examples\C_code
OriginalCSource.c  this is a straight copy and paste from http://www.sorgonet.com/linux/noise_textures/
ProceduralTexturePerlinNoise.o2bas this is a copy and paste of the C source cleaned up and setup for freeglut.

When you compile you will get errors about double definitions that do exist in the C:\Code\OxygenBasic\inc\glo2 folder

X
« Last Edit: August 05, 2012, 06:34:07 PM by kryton9 »

Charles Pegge

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #5 on: August 06, 2012, 01:41:04 PM »

Interesting algorithm, but horribly inefficient. I think I have it working in one axis.

kryton9

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #6 on: August 06, 2012, 04:14:41 PM »
I want to eventually get as many algorithms as I can and try to come up with some on my own. I thought it would be good to use freeglut to make an experimenters tool to test various algo's.

Did you get errors in the headers too?

Charles Pegge

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #7 on: August 06, 2012, 11:23:51 PM »
Hi Kent,

I had a few problems with the raw C.

Here is my interpretation, which is ~ 40X faster, has easier coloring and uses RGBA texture.

It works in the freeglut folder

Code: C
  1. indexbase 0
  2.  
  3. #include "freeglut.inc"
  4.  
  5. % ImageWidth  512
  6. % ImageHeight 512
  7.  
  8. byte MatrixImage[ImageHeight*ImageWidth*4];
  9.  
  10.  
  11. float InterPolation(float a, float b, float c)
  12. {    
  13.     return a+(b-a)*c*c*(3-2*c);                
  14.                                            
  15. }
  16.  
  17.  
  18.  
  19. float InterpLinear(float a, float b, float c)
  20. {    
  21.   return a*(1-c)+b*c;                                          
  22. }
  23.  
  24.  
  25. float Noise(int v)
  26. {
  27.   static double d=1/0x7fffffff
  28.   mov eax,v
  29.   rol eax,5
  30.   mul v
  31.   xor eax,0x9595adad
  32.   mul v
  33.   rol eax,3
  34.   and eax,0x7fffffff 'always positive
  35.  mov v,eax
  36.  return v*d 'range 0..1.0
  37. }
  38.  
  39.  
  40. void AddTex(sys i,r,g,b,a)
  41. {
  42.   sys x,y,a
  43.   float v1,v2,v3,v4,v5,v6,v7
  44.   dv=1/i
  45.   mk=i
  46.   neg mk
  47.   off=0x35353535
  48.   byte mb at (@MatrixImage)
  49.   for y=0 to <ImageWidth
  50.   {
  51.     y1=y and mk
  52.     y2=y1+i
  53.     y3=y1*ImageWidth+off
  54.     y4=y2*ImageWidth+off
  55.     for x=0 to <ImageHeight
  56.     {
  57.       x1=x and mk
  58.       x2=x1+i
  59.       v1=noise(y3+x1)
  60.       v2=noise(y3+x2)
  61.       v3=noise(y4+x1)
  62.       v4=noise(y4+x2)
  63.       '
  64.      v5=interpolation(v1,v2,(x-x1)*dv)
  65.      v6=interpolation(v3,v4,(x-x1)*dv)
  66.      v7=interpolation(v5,v6,(y-y1)*dv)
  67.      mb+=v7*r
  68.      @mb++
  69.      mb+=v7*g
  70.      @mb++
  71.      mb+=v7*b
  72.      @mb++
  73.      mb+=v7*a
  74.      @mb++
  75.    }
  76.  }
  77. }      
  78.  
  79.  
  80. void MakeImage()
  81. {
  82. 'scale,rgba bytes
  83.  '
  84. AddTex 64,100, 50, 0, 128
  85. AddTex 32, 64, 32, 0, 128
  86. AddTex 16, 48, 24, 0, 128
  87. AddTex  8, 24, 12, 0, 128
  88. AddTex  4, 12,  6, 0, 128
  89. AddTex  2,  6,  3, 0, 128
  90. AddTex  1,  3,  2, 0, 128
  91. }
  92.  
  93.  
  94.  
  95. extern cdecl
  96.  
  97. void init(void)
  98. {    
  99.  glClearColor (0.0, 0.0, 0.0, 0.0);
  100.  glShadeModel(GL_FLAT);
  101.  makeImage();
  102.  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  103. }
  104.  
  105. void display(void)
  106. {
  107.   glClear(GL_COLOR_BUFFER_BIT);
  108.   glRasterPos2i(0, 0);
  109.   glDrawPixels(ImageWidth, ImageHeight, GL_RGBA,
  110.                GL_UNSIGNED_BYTE, MatrixImage);
  111.   glFlush();
  112. }
  113.  
  114.  
  115. void reshape(int w, int h)
  116. {
  117.   glViewport(0, 0, w, h);
  118.   glMatrixMode(GL_PROJECTION);
  119.   glLoadIdentity();
  120.   gluOrtho2D(0.0, w, 0.0, h);
  121.   glMatrixMode(GL_MODELVIEW);
  122.   glLoadIdentity();
  123. }
  124.  
  125.  
  126. void keyboard(byte key, int x, int y)
  127. {
  128.   switch key
  129.     case 27:
  130.       GlutExit();
  131.     case else
  132.   end switch
  133. }
  134.  
  135. end extern
  136.  
  137. int main(int argc, char** argv)
  138. {
  139.   glutInit(argc, argv);
  140.   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  141.   glutInitWindowSize(512, 512);
  142.   glutInitWindowPosition(100, 100);
  143.   glutCreateWindow(argv[0]);
  144.   finit
  145.   init();
  146.   glutDisplayFunc(@display);
  147.   glutReshapeFunc(@reshape);
  148.   glutKeyboardFunc(@keyboard);
  149.   glutMainLoop();
  150.   return 0;
  151. }
  152. char    *argv
  153. int     argc
  154. main    argc,argv
  155.  
  156.  

Charles

X
« Last Edit: August 06, 2012, 11:29:16 PM by Charles Pegge »

kryton9

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #8 on: August 07, 2012, 01:14:43 AM »
Thanks, it looks nice. The code is something to study, will take time. Thanks again!

kryton9

  • Guest
Re: GLubyte MatrixImage[ImageHeight][ImageWidth][3]; How in O2
« Reply #9 on: August 07, 2012, 01:54:21 AM »
Just to show what your hard work lead too, I played with your program and came up with an interesting noise pattern. I took that out to photoshop and made this awesome wood texture out of it.
All stuff we can do eventually in our own engine! The ring overlay is the noise I made in your program. The underneath is another version of it that I made into a wood color in photoshop and gave it a hand wood look with painting. But both layers came from the same noise file I generated with your app.


X