Author Topic: First pixel  (Read 3226 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
First pixel
« on: June 24, 2011, 12:15:02 PM »
Deleted...
« Last Edit: May 05, 2015, 12:34:50 PM by Peter »

kryton9

  • Guest
Re: First pixel
« Reply #1 on: June 24, 2011, 01:01:43 PM »
Peter, I am not sure if this is what you are looking for, but if you do no translations and just put vertices on the screen first-- then the center of the screen is 0,0.  The lower left of the screen is -1,-1.  The top right is 1, 1.

Here is more info about pixels at this site: http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml
« Last Edit: June 24, 2011, 01:06:34 PM by kryton9 »

Charles Pegge

  • Guest
Re: First pixel
« Reply #2 on: June 24, 2011, 02:16:08 PM »

Hi Peter,

In terms of texture:

lower left 0,0 : top right 1,1

This means the y coordinate is the opposite to that of a Windows surface.

In terms of 3d geometry:

centre of viewport surface: 0,0,0
lower left -x,-y
upper right+x,+y
toward viewer =+z
away from viewer =-z

Any point of a texture can be mapped to any point on a 2d/3d surface, so you can do inverted and mirror image textures at any scale. The pixels are interpolated so you don't see pixelation when the texture is close up or enlarged.


Charles

Charles Pegge

  • Guest
Re: First pixel
« Reply #3 on: June 25, 2011, 03:43:59 AM »
Hi Peter.

I'm still not clear about the meaning of your question. Opengl does not directly deal with pixels, except when creating new textures. And all textures have to be bound to a geometric surface.

Perhaps GUI/openglWin2.o2bas will help:

The is the Scene rendering part: You can play with the texture coords and see what happens.

Code: OxygenBasic
  1.  
  2.   '-----------------------------------
  3.  'CREATE SCENE FRAME AND SWAP BUFFERS
  4.  '===================================
  5.  '
  6.  static RECT crect
  7.   static single sx,sy,sz
  8.   '
  9.  if act then
  10.   '----------
  11.  '
  12.  '
  13.  'SET THE VIEWPORT AND PERSPECTIVE
  14.  '
  15.  GetClientRect  hwnd,&cRect
  16.   glViewport 0, 0, crect.right, crect.bottom
  17.   double aspect=crect.right/crect.bottom
  18.   '
  19.  glMatrixMode   GL_PROJECTION
  20.   glLoadIdentity
  21.   gluPerspective 45, aspect, 1.0, 100
  22.   glMatrixMode   GL_MODELVIEW
  23.   glLoadIdentity
  24.   '
  25.  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  26.   glClearColor 0.5, 0, 0, 0
  27.   '
  28.  'ACTIVATE TEXTURE
  29.  '----------------
  30.  '
  31.  glEnable GL_TEXTURE_2D
  32.   glBindTexture GL_TEXTURE_2D,texn[1]
  33.   '
  34.  sx=0.2 : sy=0.16 : sz=-1
  35.   '
  36.  '
  37.  'MOVEMENT
  38.  '--------
  39.  '
  40.  'glrotatef ang1, 0,0,1
  41.  single x=cos(rad(ang1))*.1 ,y=sin(rad(ang1))*.1,z=0
  42.   gltranslatef x,y,z
  43.   '
  44.  'DRAW SHAPE
  45.  '----------
  46.  '
  47.  'this quad is drawn clockwise
  48.  '
  49.  glbegin GL_QUADS
  50.   '
  51.  glTexCoord2f 0,0 : glvertex3f -sx, -sy,  sZ
  52.   glTexCoord2f 0,1 : glvertex3f -sx,  sy,  sZ
  53.   glTexCoord2f 1,1 : glvertex3f  sx,  sy,  sZ
  54.   glTexCoord2f 1,0 : glvertex3f  sx, -sy,  sZ
  55.   '
  56.  glend
  57.   '
  58.  glDisable GL_TEXTURE_2D
  59.   '
  60.  glfinish
  61.   swapBuffers hdc
  62.   '
  63.  '
  64.  'UPDATE ROTATION ANGLES
  65.  '----------------------
  66.  '
  67.  ang1+=angi1
  68.   act=0
  69.   '
  70.  return 0 'done
  71.  

Charles
« Last Edit: June 25, 2011, 04:16:55 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: First pixel
« Reply #4 on: June 25, 2011, 08:50:04 AM »
Peter.

This will run from examples/gui

Texture Generation

Code: OxygenBasic
  1.  
  2.   'Prepare Textures
  3.  '----------------
  4.  '
  5.  glGenTextures 2, texn
  6.   '
  7.  sys res=512
  8.   sys pixels[4096], tx=64, ty=64, x, y, p, c
  9.   '
  10.  for y=1 to 64
  11.     for x=1 to 64
  12.       if x<33 and y<33
  13.         c=0xff00ff00       'GREEN BOTTOM LEFT
  14.      elseif x>32 and y>32
  15.         c=0xffff0000       'BLUE TOP RIGHT
  16.      else
  17.         c=0xff0000ff       'RED
  18.      end if
  19.       p=y*64-64+x
  20.       pixels[p]=c
  21.     next
  22.   next
  23.   '
  24.  'GL_NEAREST
  25.  'GL_LINEAR
  26.  glBindTexture GL_TEXTURE_2D, texn[1]
  27.   glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
  28.   '
  29.  'GL_NEAREST
  30.  'GL_LINEAR
  31.  'GL_NEAREST_MIPMAP_NEAREST         0x2700
  32.  'GL_LINEAR_MIPMAP_NEAREST          0x2701
  33.  'GL_NEAREST_MIPMAP_LINEAR          0x2702
  34.  'GL_LINEAR_MIPMAP_LINEAR           0x2703
  35.  '
  36.  glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
  37.   glTexImage2D GL_TEXTURE_2D, 0, 4, tx, ty, 0, GL_RGBA, GL_UNSIGNED_BYTE, @Pixels
  38.   '
  39.  return 0
  40.   '
  41.  

Texture binding as before

Code: OxygenBasic
  1.  
  2.   glbegin GL_QUADS
  3.   '
  4.  glTexCoord2f 0,0 : glvertex3f -sx, -sy,  sZ 'BOTTOM LEFT
  5.  glTexCoord2f 0,1 : glvertex3f -sx,  sy,  sZ 'TOP LEFT
  6.  glTexCoord2f 1,1 : glvertex3f  sx,  sy,  sZ 'TOP RIGHT
  7.  glTexCoord2f 1,0 : glvertex3f  sx, -sy,  sZ 'BOTTOM RIGHT
  8.  '
  9.  glend
  10.  

Charles

Charles Pegge

  • Guest
Re: First pixel
« Reply #5 on: June 25, 2011, 07:24:35 PM »

Do any of the other Opengl examples crash your PC Peter? This one is based on the examples/OpenglWin series. The only significant difference is the pixels texture making routine.

Charles