Author Topic: rotating sphere + texture question  (Read 1924 times)

0 Members and 1 Guest are viewing this topic.

Frankolinox

  • Guest
rotating sphere + texture question
« on: May 22, 2013, 12:43:48 AM »
topic: openGL, texture

I wanted a rotating sphere as planet instead of a cube for texturing. the parameter for "rendersphere" function may be wrong and the coordinates. any help is welcome. thanks in advance.

Code: [Select]
 includepath "$\inc\"
  $ FileName "t.exe"
  'include "RTL32.inc"
  'include "RTL64.inc"
  title="MarsPlanet in Fog"
  include "OpenglSceneFrame.inc"
  includepath ""
  include "shapes.inc"
  include "particles.inc"
  include "materials.inc"

  indexbase 1
  sys   texn[3]
  sys   GdiplusToken
  float ang1
  float li[16]
  float ma[13]
  sys cube pent
  sys sphere
    

  sub initialize(sys hWnd)
  ========================
  '
  'GDIPLUS
  '
  sys hr
  GdiplusStartupInput StartupInput

  StartupInput.GdiplusVersion = 1
  hr=GdiplusStartup GdiplusToken, StartupInput, null
  '
  if hr then
    print "Error initializing GDIplus: " hex hr
    exit function
  end if
  '
  'PREPARE TEXTURES
  '
  glGenTextures 2, texn
  '
  static sys res=256
  string imgs[1]=""
  string imgs[2]=""
  'GetTexImage "../images/crate.jpg",res,imgs[1]
  GetTexImage "hubble_mars.bmp",res,imgs[1]
  MakeTexture *imgs[1],res,res,texn[1]
  '
  cube=CompileList : CubeForm    : glEndList
  pent=CompileList : Sides 5,1,1 : glEndList
  sphere=CompileList : Spheric 1,1,6 : glEndList
  '
  'standard lighting
  ------------------
  li<=
  0.0, 8.0, 8.0, 1.0,  'position
  1.0, 1.0, 1.0, 1.0,  'ambient
  1.0, 1.0, 1.0, 1.0,  'diffuse
  1.0, 1.0, 1.0, 1.0   'specular

  'standard material
  ------------------
  ma<=
  .15, .15, 0.2, 1.0, 'ambient
  0.7, 0.7, 0.6, 1.0, 'diffuse
  0.0, 0.0, 0.1, 1.0, 'specular  
  0                   'shininess
  Material ma
  Lighting li
  '
  '
  SetTimer hWnd,1,10,null
  end sub

  sub Release(sys hwnd)
  '====================
  glDeleteLists    cube,1
  glDeleteLists    pent,1
  glDeleteTextures 2, texn
  GdiplusShutdown GdiplusToken
  killTimer hwnd, 1
  end sub
  '
  '---------- test --------------------------------- //
  sub RenderSphere(float x,y,z,sc,sys tex) 'spheric
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,tex
  glPushMatrix
  gltranslatef x,y,z
  glrotatef    ang1,0,1,0
  glscalef sc,sc,sc
  glCallList sphere
  'glCallList Pent
  glPopMatrix
  glDisable GL_TEXTURE_2D
  end sub
  '---------- test --------------------------------- //

  sub RenderCrate(float x,y,z,sc,sys tex)
  =======================================
  'glColor4f .99,.99,.99,.99
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,tex
  glPushMatrix
  gltranslatef x,y,z
  glrotatef    ang1,0,1,0
  glscalef sc,sc,sc
  glCallList Cube
  'glCallList Pent
  glPopMatrix
  glDisable GL_TEXTURE_2D
  end sub


  sub scene(sys hWnd)
  '==================
  '
  'Ctrl-P take snapshot
  '
  static sys photo
  if key[80] and key[17] and photo=0
    TakeOpenglSnapShot hwnd,"tim50.jpg","image/jpeg",50
    photo=1
  elseif key[80]=0
    photo=0
  end if

  static single ra,ri,angi1=.5
  '
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  glEnable GL_DEPTH_TEST
  glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
  glEnable GL_BLEND
  glLoadIdentity
  '
  glClearColor 0.5, 0.5, 0.7, 0
  '
  float fcolor[4]={.5, .5, .7, .99}
  glfogi GL_FOG_MODE,GL_EXP
  glfogf GL_FOG_DENSITY,0.1
  glfogfv GL_FOG_COLOR,  fcolor
  glfogf GL_FOG_INDEX,  0
  glfogf GL_FOG_START, -1.0
  glfogf GL_FOG_END,   -100.0
  glEnable GL_FOG
  '
  glEnable GL_LIGHTING
  glEnable GL_NORMALIZE
  glColor4f .99,.99,.99,.99
  'sys n=texn[1]
  'RenderCrate  11.5,-0.9,-24.0,0.5,n
  'RenderCrate   6.5,-0.9,-16.0,0.5,n
  'RenderCrate   2.5,-0.9,-8.0, 0.5,n
  'RenderCrate   0.5,-0.9,-4.0, 0.5,n
  'RenderCrate  -0.5,-0.9,-2.0, 0.5,n
  '
  sys n=texn[1]
  RenderSphere  11.5,-0.9,-24.0,0.5,n
  RenderSphere   6.5,-0.9,-16.0,0.5,n
  RenderSphere   2.5,-0.9,-8.0, 0.5,n
  RenderSphere   0.5,-0.9,-4.0, 0.5,n
  RenderSphere  -0.5,-0.9,-2.0, 0.5,n
  
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

frank

X

Charles Pegge

  • Guest
Re: rotating sphere + texture question
« Reply #1 on: May 22, 2013, 11:39:37 PM »
Hi Frank,

I'm working on sphere textures and terrain. Curved surface have to be divided into facets, so that textures can be mapped onto them. Cubic texture mapping gives the best distribution of facets. If all goes well we will enventually be able to land on the planets :)

Charles

Frankolinox

  • Guest
Re: rotating sphere + texture question
« Reply #2 on: May 27, 2013, 02:08:19 AM »
I have a simple question: if I want to use the "keyboard" functions "key[37]" for example where I have to program for using it (I want to move a cube by pushing keys) with keys?

a) below wndproc() from the inc file part or b) directly below openGL "scene" part ?

thanks in advance, frank