Page 3 sur 4

Publié : mer. 05/juil./2006 21:54
par djes
Cpl.Bator a écrit :Merci , tonton , c'est bien ce qu'il me semblait !
je cherchais dans ton code la formule de projection, j'ai vu que tu traite l'info directement sur la matrice, je vais en faire de meme, je vais en chier pour comprendre d'ou sorte toutes tes variables :D
je vais faire des tests, si cela est concluant, je met le code pour qu'il soit compréhensible de tous, puis je diffuse sur le forum.

@Djes, j'ai vu l'include OpenGL, Fonctionne t'il ? car je ne vois que les objet en wireframe.


En tout cas merci encore :!:
Oui l'include Opengl fonctionne, mais ne sert pas dans mon exemple ;) Voici un code qui s'en sert. (pas de moi)

Code : Tout sélectionner

;- Program Includes

XIncludeFile "include\OpenGL.pb"

;- Program Constants

#Clear_Red=0.0
#Clear_Green=0.0
#Clear_Blue=0.0
#Clear_Alpha=1.0
#NearClip=-1
#FarClip=1

; Some Window's Constants that were not defined
#DM_BITSPERPEL=$40000
#DM_PELSWIDTH=$80000
#DM_PELSHEIGHT=$100000
#CDS_FULLSCREEN=4
#DISP_CHANGE_SUCCESSFUL=0
#SC_MONITORPOWER=$F170

;- Program Globals

Global hwnd.l
Global hdc.l
Global hrc.l
Global hInstance.l


Global Dim Keys.b(256)
Global Active.b
Global Fullscreen.b

;defaults
Active=#True
Fullscreen=#True

;- Program Procedures

Procedure ResizeScreen(Width, Height) ;returns nothing
  glViewport_(0, 0, Width, Height)
  glMatrixMode_(#GL_PROJECTION)
	glLoadIdentity_()
	glOrtho_(0, Width, Height, 0, #NearClip, #FarClip)
  glMatrixMode_(#GL_MODELVIEW)
	glLoadIdentity_()
EndProcedure

Procedure RendererInit() ;returns a nothing
  glShadeModel_(#GL_SMOOTH)
  glClearColor_(#Clear_Red, #Clear_Green, #Clear_Blue, #Clear_Alpha)
  glClearDepth_(1.0)
  glDepthFunc_(#GL_LEQUAL)
  glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST)
  ProcedureReturn #True
EndProcedure

Procedure.b DrawScene() ;returns a bool
  SwapBuffers_(hdc)
  glClear_(#GL_COLOR_BUFFER_BIT|#GL_DEPTH_BUFFER_BIT)
EndProcedure

Procedure.b DestroyScreen() ;returns a nothing
  If Fullscreen
    ChangeDisplaySettings_(#Null,0)
    ShowCursor_(#True)
  EndIf
  If hrc
    If wglMakeCurrent_(#Null,#Null)
    Else
      MessageRequester("Error","The Release of DC and RC Failed!",#MB_OK|#MB_ICONINFORMATION)
    EndIf
    If wglDeleteContext_(hrc)
    Else
      MessageRequester("Error","The Release of the Rendering Context Failed!",#MB_OK|#MB_ICONINFORMATION)
    EndIf
    hrc=#Null
  EndIf
  If hdc And ReleaseDC_(hwnd,hdc)
  Else
    MessageRequester("Error","The Release of the Device Context Failed!",#MB_OK|#MB_ICONINFORMATION)
    hdc=#Null
  EndIf
  If hwnd And DestroyWindow_(hwnd)
  Else
    MessageRequester("Error","Could Not Release hwnd",#MB_OK|#MB_ICONINFORMATION)
    hwnd=#Null
  EndIf
  If UnregisterClass_("OpenGL",hInstance)
  Else
    MessageRequester("Error","Could Not Unregister Class!",#MB_OK|#MB_ICONINFORMATION)
    hInstance=#Null
  EndIf
EndProcedure

Procedure.l WindowCallback(phwnd.l,uMsg.l,wParam.l,lParam.l) ;returns a Long
  Select uMsg
    Case #WM_ACTIVATE
      If ~wParam>>8
        Active=#True
      Else
        Active=#False
      EndIf
      ProcedureReturn 0
    Case #WM_SYSCOMMAND
      Select wParam
        Case #SC_SCREENSAVE
          ProcedureReturn 0
        Case #SC_MONITORPOWER
          ProcedureReturn 0
      EndSelect
    Case #WM_CLOSE
      PostQuitMessage_(0)
      ProcedureReturn 0
    Case #WM_KEYDOWN
      Keys(wParam)=#True
      ProcedureReturn 0
    Case #WM_KEYUP
      Keys(wParam)=#False
      ProcedureReturn 0
    Case #WM_SIZE
      ResizeScreen(wParam&$00FF,Value>>8)
      ProcedureReturn 0
    Default
      ProcedureReturn DefWindowProc_(phwnd,uMsg,wParam,lParam)
  EndSelect
EndProcedure

Procedure.b CreateScreen(Title.s,Width.l,Height.l,Bits.l,FullscreenFlag.b) ;returns a Bool
  PixelFormat.l
  WC.WNDCLASS
  ExStyle.l
  style.l
  WindowRect.RECT
  
  WindowRect\left=0
  WindowRect\right=Width
  WindowRect\top=0
  WindowRect\bottom=Height
  
  Fullscreen=FullscreenFlag
  hInstance=GetModuleHandle_(#Null)
  
  WC\style=#CS_HREDRAW|#CS_VREDRAW|#CS_OWNDC
  WC\lpfnWndProc=@WindowCallback()
  WC\cbClsExtra=0
  WC\cbWndExtra=0
  WC\hInstance=hInstance
  WC\hIcon=LoadIcon_(#Null, #IDI_WINLOGO)
  WC\hCursor=LoadCursor_(#Null, #IDC_ARROW)
  WC\hbrBackground=#Null
  WC\lpszMenuName=#Null
  WC\lpszClassName=@"OpenGL"
  
  If RegisterClass_(WC)
  Else
    MessageRequester("Error", "Failed To Register The Window Class!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  If Fullscreen
    DMScreenSettings.DEVMODE
    DMScreenSettings\dmSize=SizeOf(DEVMODE)
    DMScreenSettings\dmPelsWidth=Width
    DMScreenSettings\dmPelsHeight=Height
    DMScreenSettings\dmBitsPerPel=Bits
    DMScreenSettings\dmFields=#DM_BITSPERPEL|#DM_PELSWIDTH|#DM_PELSHEIGHT
    If ChangeDisplaySettings_(DMScreenSettings,#CDS_FULLSCREEN)<>#DISP_CHANGE_SUCCESSFUL
      If MessageRequester("Error","The Requested Fullscreen Mode Is Not Supported By "+Chr(10)+"Your Video Card. Use Windowed Mode Instead?",#MB_YESNO|#MB_ICONEXCLAMATION)=#IDYES
        Fullscreen=#False
      Else
        MessageRequester("Error","Could Not Open Full Screen!",#MB_OK|#MB_ICONSTOP)
      EndIf
      ProcedureReturn #False
    EndIf
  EndIf
  
  If Fullscreen
    ExStyle=#WS_EX_APPWINDOW|#WS_EX_WINDOWEDGE
    style=#WS_POPUP
    ShowCursor_(#False)
  Else
    ExStyle=#WS_EX_APPWINDOW|#WS_EX_WINDOWEDGE
    style=#WS_OVERLAPPEDWINDOW
  EndIf
  
  AdjustWindowRectEx_(WindowRect,style,#False,ExStyle)
  hwnd=CreateWindowEx_(ExStyle,"OpenGL",Title,Style|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,WindowRect\right-WindowRect\left,WindowRect\bottom-WindowRect\top,#Null,#Null,hInstance,#Null)
  
  If hwnd
  Else
    DestroyScreen()
    MessageRequester("Error","Cannot Create Window!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  pfd.PIXELFORMATDESCRIPTOR
  pfd\nSize=SizeOf(PIXELFORMATDESCRIPTOR)
  pfd\nVersion=1
  pfd\dwFlags=#PFD_DRAW_TO_WINDOW|#PFD_SUPPORT_OPENGL|#PFD_DOUBLEBUFFER
  pfd\iPixelType=#PFD_TYPE_RGBA
  pfd\cColorBits=Bits
  pfd\cRedBits=0
  pfd\cRedShift=0
  pfd\cGreenBits=0
  pfd\cGreenShift=0
  pfd\cBlueBits=0
  pfd\cBlueShift=0
  pfd\cAlphaBits=0
  pfd\cAlphaShift=0
  pfd\cAccumBits=0
  pfd\cAccumRedBits=0
  pfd\cAccumGreenBits=0
  pfd\cAccumBlueBits=0
  pfd\cAccumAlphaBits=0
  pfd\cDepthBits=16
  pfd\cStencilBits=0
  pfd\cAuxBuffers=0
  pfd\iLayerType=#PFD_MAIN_PLANE
  pfd\bReserved=0
  pfd\dwLayerMask=0
  pfd\dwVisibleMask=0
  pfd\dwDamageMask=0
  
  hdc=GetDC_(hwnd)
  
  If hdc
  Else
    DestroyScreen()
    MessageRequester("Error","Can't Create a GL Device Context!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  
  PixelFormat=ChoosePixelFormat_(hdc,pfd)
  
  If PixelFormat
  Else
    DestroyScreen()
    MessageRequester("Error","Cannot Find a Suitable PixelFormat!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  
  If SetPixelFormat_(hdc,PixelFormat,pfd)
  Else
    DestroyScreen()
    MessageRequester("Error","Cannot Set The PixelFormat!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  
  hrc=wglCreateContext_(hdc)
  
  If hrc
  Else
    DestroyScreen()
    MessageRequester("Error","Cannot Create a GL Rendering Context!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  
  If wglMakeCurrent_(hdc,hrc)
  Else
    DestroyScreen()
    MessageRequester("Error","Cannot Activate The GL Rendering Context!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  
  ShowWindow_(hwnd,#SW_SHOW)
  SetForegroundWindow_(hwnd)
  SetFocus_(hwnd)
  ResizeScreen(Width,Height)
  
  If RendererInit()
  Else
    DestroyScreen()
    MessageRequester("Error","Cannot Initialize OpenGL!",#MB_OK|#MB_ICONEXCLAMATION)
    ProcedureReturn #False
  EndIf
  
  ProcedureReturn #True
EndProcedure

Procedure ScreenEvent()
  msg.MSG
  PeekMessage_(msg,#Null,0,0,#PM_REMOVE)
  WindowCallback(hwnd,msg\message,msg\wParam,msg\lParam)
  If msg
    If msg\message=#WM_QUIT
      DestroyScreen()
      End
    EndIf
  Else
    TranslateMessage_(msg)
    DispatchMessage_(msg)
  EndIf
  ProcedureReturn msg\message
EndProcedure

Procedure StartRendering()
  glBegin_(#GL_POINTS)
EndProcedure

Procedure StopRendering()
  glEnd_()
EndProcedure

Procedure FlipAndClear()
  SwapBuffers_(hdc)
  glClear_(#GL_COLOR_BUFFER_BIT|#GL_DEPTH_BUFFER_BIT)
EndProcedure

;- Program Entry Point

;********************************
;*Name: Fire                    *
;*By: Dreglor                   *
;*last updated: 8-31-05 6:11pm  *
;********************************

y.w=0
x.w=0
screen_width.w=1024
screen_height.w=768
Dim cool.w(screen_width,screen_height)
Dim buf.w(screen_width,screen_height)
yy.w=0
xx.w=0
For y=1 To screen_height-1
  For x=1 To screen_width-1
    cool(x,y)=Random(3)
    buf(x,y)=0
  Next x
Next y
Dim color(255)
For i=0 To 84
  color(i)=Int(255/84*i)+0<<8+0<<16
  color(i+85)=255+Int(255/84*i)<<8+0<<16
  color(i+85+85)=255+255<<8+Int(255/84*i)<<16
Next i

If MessageRequester("Start FullScreen?","Would You Like To Run In Fullscreen Mode?",#MB_YESNO|#MB_ICONQUESTION)=#IDNO
  Fullscreen=#False
EndIf

If CreateScreen("PB With OpenGL!",screen_width,screen_height,32,Fullscreen)
Else
  End
EndIf

While done<>#True
  msg=ScreenEvent()
  If Active
    If Keys(#VK_ESCAPE)
      done=#True
    Else
      glBegin_(#GL_POINTS)
      For y=1 To screen_height-1
        For x=1 To screen_width-1
          If buf(x,y) > 0
            If buf(x,y) < 0
              buf(x,y)=0
            Else
              buf(x,y)=((buf(x+1,y)+buf(x-1,y)+buf(x,y+1)+buf(x,y-1))/4-cool(x,y))
            EndIf       
            buf(x,y-1)=buf(x,y)
            cool(x,y-1)=cool(x,y)
            cool(x,y)=Random(3)
            If buf(x,y) > 0
              ;Plot(x,y,color(buf(x,y)))
              muiltplier.f=1
              red.f=Red(color(buf(x,y)))/255
              green.f=Green(color(buf(x,y)))/255
              blue.f=Blue(color(buf(x,y)))/255
              glColor4f_(red,green,blue,1.0)
              glVertex2i_(x,y)
            EndIf
          EndIf
          buf(x,screen_height-2)=255
        Next x
      Next y
      glEnd_()
      FlipAndClear()
      
    EndIf
    If Keys(#VK_F1)
      Keys(#VK_F1)=#False
      DestroyScreen()
      Fullscreen=~Fullscreen
      If CreateScreen("PB With OpenGL!",screen_width,screen_height,32,Fullscreen)
      Else
        End
      EndIf
    EndIf
  EndIf
Wend
DestroyScreen()
End
EDIT: Correction du code

Publié : mer. 05/juil./2006 22:02
par Anonyme
Merki djes ! :wink:

Publié : jeu. 06/juil./2006 20:34
par Anonyme
Voici les niouzes, après de longue bataille, j'ai à peu près reussi l'implémentation d'une caméra, mais en ayant tester l'exemple de djes, je me suis dit pourquoi ne pas combiné OpenGL et mes objets ?
en fait la mise en place d'openGL est super simple, on ne gère pas directement les matrices, en plus des tutos regorge sur le net !

File:1->OpenGL.rar
Image

je vous l'accorde, rien de complexe, mais j'chui content du resultat :D
je met le code au propre et je le diffuse !

@Djes
Je voulais savoir comment faire pour obtenir un contexte ecran pour opengl (comme dans ton exemple) mais avec une icone reduire, fermer, et comment avoir un véritable plein écran? j'y connais rien en gestion des api windows :oops:

Publié : jeu. 06/juil./2006 22:20
par TersaKen
Tres Joli, je me pencherais sur le sujet plus tard :D un peu rapide cependant :D non franchement c'est super interessant, et je partage ton enthousiasme ;)

Bonne continuation c'est genial !

Publié : jeu. 06/juil./2006 22:28
par Anonyme
Merci, c'est surement adaptable pour ton projet de raycasting.
enfin, ca dépend comment tu gére tes faces et les UV de ces faces.

Code : Tout sélectionner

glTexCoord2d_(U,V)    :  glVertex3d_(x,y,z)
glTexCoord2d_(0,0)     :  glVertex3d_(-10,-10,-1)
glTexCoord2d_(10,0)   :  glVertex3d_(10,-10,-1)
glTexCoord2d_(10,10)  :  glVertex3d_(10,10,-1)
glTexCoord2d_(0,10)   :  glVertex3d_(-10,10,-1)
je met tout au propre vite fait, et je met le tout en ligne ^^

Publié : jeu. 06/juil./2006 22:35
par Frenchy Pilou
Dans ce cas particulier où il a quelque chose à lire sur le cube,
il vaudrait mieux le faire tourner dans l'autre sens,
car la lecture se faisant chez nous de gauche à droite,
il faut donc le faire tourner dans le sens "horlogique" :D
Sinon on va se chopper un super mal de crâne :)

Publié : ven. 07/juil./2006 10:04
par Progi1984
Tiens un début de moteur 3D que j'avais voulu faire en PB

Code : Tout sélectionner

XIncludeFile "OpenGL.pb" 

;-Constantes
#WindowWidth = 800
#WindowHeight = 600
#WindowFlags = #PB_Window_TitleBar | #PB_Window_MaximizeGadget | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered

;-Déclarations
Declare CreateGLWindow()
Declare TFE_CreateCube()
Declare TFE_TranslateEntity(entity,x.f,y.f,z.f)
Declare TFE_RenderWorld()
Declare TFE_SetScale(entity,x.f,y.f,z.f)
Declare GL_Callback(WindowID, Message, wParam, lParam)

;-Globales
Global Nb_objets.w:Nb_objets=0
Global hWndGL.l,hDc
;-Constantes
#Nb_vertex=2000
#Nb_polygones=2000
;-Structures
Structure TVertex
  x.f
  y.f
  z.f
EndStructure
Structure TPolygone
  ida.w
  idb.w
  idc.w
EndStructure
Structure TObjet
  Vertex.TVertex[#Nb_vertex]
  Polygone.TPolygone[#Nb_polygones]
  Nb_Vertex.w
  Nb_Polygone.w
  Scale_x.f
  Scale_y.f
  Scale_z.f
  Rotate_x.f
  Rotate_y.f
  Rotate_z.f
EndStructure
;-Tableaux

Dim Objet.Tobjet(1000)
Global piover180.f, hWnd.l, FOV.f, gluObj, CamSpeed.f, CameraX.f, CameraY.f, CameraZ.f, CamrotX.f, CamrotY.f, CamrotZ.f
;-Initialisations
level=0
etape.f=1.0
;
cube=TFE_CreateCube()
;cube2=TFE_CreateCube()
TFE_SetScale(cube,0.75,0.75,0.75)

If OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #WindowFlags, "Mon ti moteur3D")
  SetWindowCallback(@GL_Callback())
  CreateGLWindow()
  
  glEnable_(#GL_FOG) ;enable standard fog(glEnable activates a OpenGL feature)
  glEnable_(#GL_DEPTH_TEST)
  glEnable_(#GL_CULL_FACE)
  glMatrixMode_(#GL_PROJECTION)
  glMatrixMode_ (#GL_MODELVIEW) 
  Repeat
    Select level
      Case 0
        etape=etape-0.01
        TFE_SetScale(cube,etape,etape,etape)
        If etape<=0:level=1:etape=0:EndIf
      Case 1
        etape=etape+0.01
        TFE_SetScale(cube,etape,etape,etape)
        If etape=>1:level=2:etape=1:EndIf
      Case 2
        etape=etape-0.01
        TFE_SetScale(cube,etape,etape,etape)
        If etape<=0.75:level=3:etape=0.8:EndIf
      Case 3
        etape=etape-0.02
        TFE_TranslateEntity(cube,0.01,0,0)
        If etape<=0.2:level=4:etape=0.2:EndIf      
      Case 4
        etape=etape+0.02
        TFE_TranslateEntity(cube,-0.01,0,0)
        If etape>=0.9:level=5:etape=0.9:EndIf  
      Case 5
        etape=etape-0.02
        TFE_TranslateEntity(cube,0,-0.1,0)
        If etape<=0.2:level=6:etape=0.2:EndIf        
      Case 6
        etape=etape+0.02
        TFE_TranslateEntity(cube,0,0.1,0)
        If etape>=0.56:level=9:etape=0.56:EndIf   
      Case 7
      Case 8
      Case 9
        End
    EndSelect
    TFE_RenderWorld()
    Event = WindowEvent() ;We should use WindowEvent, because the Animation shouldn't stop
    Delay(5)

  Until Event = #PB_Event_CloseWindow
  End
EndIf

Procedure CreateGLWindow()
  hWndGL = WindowID(0)  ;create a handle to the window
  pfd.PIXELFORMATDESCRIPTOR   ;start opengl
  hDC = GetDC_(hWndGL)
  pfd\nSize        = SizeOf(PIXELFORMATDESCRIPTOR)
  pfd\nVersion     = 1
  pfd\dwFlags      = #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER | #PFD_DRAW_TO_WINDOW
  pfd\iLayerType   = #PFD_MAIN_PLANE
  pfd\iPixelType   = #PFD_TYPE_RGBA
  pfd\cColorBits   = 24  ;colorbuffer(24bit)
  pfd\cDepthBits   = 32  ;depthbuffer
  pixformat = ChoosePixelFormat_(hDC, pfd)
  SetPixelFormat_(hDC, pixformat, pfd)
  hrc = wglCreateContext_(hDC)
  wglMakeCurrent_(hDC, hrc)
  SwapBuffers_(hDC) ;in purebasic you have to call this command once at the start.
  glClearColor_(0.0, 0.0, 0.0, 0.0) ;Backgroundcolor (Parameters: (1/255)*Red, (1/255)*Green, (1/255)*Blue, Alpha)
  glEnable_(#GL_DEPTH_TEST)
EndProcedure

Procedure TFE_CreateCube()
  Objet(Nb_Objets)\vertex[0]\x=0;  
  Objet(Nb_Objets)\vertex[0]\y=0;  
  Objet(Nb_Objets)\vertex[0]\z=0; //vertex v0
  Objet(Nb_Objets)\vertex[1]\x=1;  
  Objet(Nb_Objets)\vertex[1]\y=0;  
  Objet(Nb_Objets)\vertex[1]\z=0; //vertex v1
  Objet(Nb_Objets)\vertex[2]\x=1;  
  Objet(Nb_Objets)\vertex[2]\y=0;  
  Objet(Nb_Objets)\vertex[2]\z=1; //vertex v2
  Objet(Nb_Objets)\vertex[3]\x=0;  
  Objet(Nb_Objets)\vertex[3]\y=0;  
  Objet(Nb_Objets)\vertex[3]\z=1; //vertex v3
  Objet(Nb_Objets)\vertex[4]\x=0;  
  Objet(Nb_Objets)\vertex[4]\y=1;  
  Objet(Nb_Objets)\vertex[4]\z=0; //vertex v4
  Objet(Nb_Objets)\vertex[5]\x=1;  
  Objet(Nb_Objets)\vertex[5]\y=1;  
  Objet(Nb_Objets)\vertex[5]\z=0; //vertex v5
  Objet(Nb_Objets)\vertex[6]\x=1;  
  Objet(Nb_Objets)\vertex[6]\y=1;  
  Objet(Nb_Objets)\vertex[6]\z=1; //vertex v6
  Objet(Nb_Objets)\vertex[7]\x=0;  
  Objet(Nb_Objets)\vertex[7]\y=1;  
  Objet(Nb_Objets)\vertex[7]\z=1; //vertex v7
  
  Objet(Nb_Objets)\Nb_vertex=7
  
  Objet(Nb_Objets)\polygone[0]\ida=0
  Objet(Nb_Objets)\polygone[0]\idb=1
  Objet(Nb_Objets)\polygone[0]\idc=4
  
  Objet(Nb_Objets)\polygone[1]\ida=1
  Objet(Nb_Objets)\polygone[1]\idb=5
  Objet(Nb_Objets)\polygone[1]\idc=4

  Objet(Nb_Objets)\polygone[2]\ida=1
  Objet(Nb_Objets)\polygone[2]\idb=2
  Objet(Nb_Objets)\polygone[2]\idc=5

  Objet(Nb_Objets)\polygone[3]\ida=2
  Objet(Nb_Objets)\polygone[3]\idb=6
  Objet(Nb_Objets)\polygone[3]\idc=5

  Objet(Nb_Objets)\polygone[4]\ida=2
  Objet(Nb_Objets)\polygone[4]\idb=3
  Objet(Nb_Objets)\polygone[4]\idc=6

  Objet(Nb_Objets)\polygone[5]\ida=3
  Objet(Nb_Objets)\polygone[5]\idb=7
  Objet(Nb_Objets)\polygone[5]\idc=6

  Objet(Nb_Objets)\polygone[6]\ida=3
  Objet(Nb_Objets)\polygone[6]\idb=0
  Objet(Nb_Objets)\polygone[6]\idc=7

  Objet(Nb_Objets)\polygone[7]\ida=0
  Objet(Nb_Objets)\polygone[7]\idb=4
  Objet(Nb_Objets)\polygone[7]\idc=7

  Objet(Nb_Objets)\polygone[8]\ida=4
  Objet(Nb_Objets)\polygone[8]\idb=5
  Objet(Nb_Objets)\polygone[8]\idc=7

  Objet(Nb_Objets)\polygone[9]\ida=5
  Objet(Nb_Objets)\polygone[9]\idb=6
  Objet(Nb_Objets)\polygone[9]\idc=7

  Objet(Nb_Objets)\polygone[10]\ida=3
  Objet(Nb_Objets)\polygone[10]\idb=2
  Objet(Nb_Objets)\polygone[10]\idc=0

  Objet(Nb_Objets)\polygone[11]\ida=2
  Objet(Nb_Objets)\polygone[11]\idb=1
  Objet(Nb_Objets)\polygone[11]\idc=0
  
  Objet(Nb_Objets)\Nb_Polygone=11
  
  Objet(Nb_Objets)\Scale_X=1.0
  Objet(Nb_Objets)\Scale_Y=1.0
  Objet(Nb_Objets)\Scale_Z=10
  Objet(Nb_Objets)\Rotate_X=0
  Objet(Nb_Objets)\Rotate_Y=0
  Objet(Nb_Objets)\Rotate_Z=0
  Nb_objets=Nb_objets+1
  ProcedureReturn Nb_objets-1
EndProcedure
Procedure TFE_RenderWorld()
    ;-
    ;-
    ;-
;     glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT) ; Delete
;     glMatrixMode_(#GL_PROJECTION) ;Clipplane
;     glLoadIdentity_()
;     gluPerspective__(FOV, WindowWidth()/WindowHeight(), 0.01, 20.0) ;define view
;     gluLookAt__(-CameraX, -CameraY, -CameraZ, -(CameraX + Sin(CamrotY*piover180)*10), 0, -(CameraZ + Cos(CamrotY*piover180)*10)+1, 0.0, 1.0, 0.0)
;     glMatrixMode_(#GL_MODELVIEW)
;     glLoadIdentity_()
;      ;GetAsyncKeyState_() = WinAPI command To get the keystates
;     If GetAsyncKeyState_(#VK_UP) <> 0
;       CameraZ = CameraZ + Cos(CamrotY*piover180)*CamSpeed/5 ; Walk to seeposition
;       CameraX = CameraX + Sin(CamrotY*piover180)*CamSpeed/5
;     ElseIf GetAsyncKeyState_(#VK_DOWN) <> 0
;         CameraZ = CameraZ - Cos(CamrotY*piover180)*CamSpeed/5 ; Walk away from seeposition
;         CameraX = CameraX - Sin(CamrotY*piover180)*CamSpeed/5
;     EndIf
;     If GetAsyncKeyState_(#VK_RIGHT) <> 0  ;camerarotation
;       CamrotY - (CamSpeed*10) ;rotate
;     ElseIf GetAsyncKeyState_(#VK_LEFT) <> 0
;       CamrotY + (CamSpeed*10) ;rotate
;     EndIf
    ;-
    ;-
    ;-  
     ;active le mode fil de fer
 ;   glPolygonMode_(#GL_FRONT_AND_BACK,#GL_LINE);
  For i=0 To Nb_objets-1
    glLoadIdentity_() ;create a new Object

    glTranslatef_(0.0, 0.25, 0.0) ; move 0.25 up
    glRotatef_(Objet(i)\Rotate_x, 1.0, 0.0, 0.0) ;rotate around x, y and z
    glRotatef_(Objet(i)\Rotate_y, 0.0, 1.0, 0.0)
    glRotatef_(Objet(i)\Rotate_z, 0.0, 0.0, 1.0)
    glScalef_(Objet(i)\Scale_X, Objet(i)\Scale_Y, Objet(i)\Scale_Z) ;scale with the scalefaktor 0.75

    glBegin_(#GL_TRIANGLES) ;start with the drawing(you can also create quadratics or polygons with #GL_QUADS, ...)

    For j=0 To Objet(i)\Nb_Polygone
      glColor3f_(1.0,0.0,0.0)   
      glVertex3f_(objet(i)\vertex[objet(i)\polygone[j]\ida]\x, objet(i)\vertex[objet(i)\polygone[j]\ida]\y, objet(i)\vertex[objet(i)\polygone[j]\ida]\z)
      glColor3f_(0.0,1.0,0.0);
      glVertex3f_( objet(i)\vertex[objet(i)\polygone[j]\idb]\x, objet(i)\vertex[objet(i)\polygone[j]\idb]\y, objet(i)\vertex[objet(i)\polygone[j]\idb]\z)
      glColor3f_(0.0,0.0,1.0);
      glVertex3f_( objet(i)\vertex[objet(i)\polygone[j]\idc]\x, objet(i)\vertex[objet(i)\polygone[j]\idc]\y, objet(i)\vertex[objet(i)\polygone[j]\idc]\z)
    Next
    glEnd_()
  Next
     
  SwapBuffers_(hDC) ;draw
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
EndProcedure
Procedure TFE_TranslateEntity(entity,x.f,y.f,z.f)
  For i=0 To Objet(entity)\Nb_Vertex
    Objet(entity)\vertex[i]\x=Objet(entity)\vertex[i]\x+x  
    Objet(entity)\vertex[i]\y=Objet(entity)\vertex[i]\y+y  
    Objet(entity)\vertex[i]\z=Objet(entity)\vertex[i]\z+z
  Next
EndProcedure
Procedure TFE_SetScale(entity,x.f,y.f,z.f)
  Objet(entity)\Scale_X=x
  Objet(entity)\Scale_Y=y
  Objet(entity)\Scale_Z=z
EndProcedure

Procedure GL_Callback(WindowID, Message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  If Message = #WM_SIZE
    glViewport_(0, 0, WindowWidth(), WindowHeight())  ;Resize the OpenGLscene
    Result = 1
  EndIf
  ProcedureReturn Result
EndProcedure









; IDE Options = PureBasic v3.94 (Windows - x86)
; CursorPosition = 64
; FirstLine = 15
; Folding = g5

Publié : ven. 07/juil./2006 10:11
par Anonyme
super, je vais te piquer la création de contexte :wink:

Publié : sam. 08/juil./2006 17:09
par djes
Excuse, il y avait un bug dans la création de la fenêtre. Le bon code est celui-ci.

Code : Tout sélectionner

  hwnd=CreateWindowEx_(ExStyle,"OpenGL",Title,style|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,WindowRect\right-WindowRect\left,WindowRect\bottom-WindowRect\top,#Null,#Null,hInstance,#Null)

Publié : sam. 08/juil./2006 17:34
par tonton
ben alore mon caporal.....tu t éloignes de ton objectif.
l opengl, c est de la tripaille prefabriquée. 8)

Publié : sam. 08/juil./2006 17:37
par Anonyme
non, non pas du tout , cela me permet en autres comment les matrices de transformation sont gerer :wink:

Publié : mar. 12/déc./2006 23:41
par Anonyme
Recoucou à tous, j'ai repris le code du moteur à 0
voici la première mouture :
File:1->SoftEngine3D.rar
Image

j'aurais besoin de vos avis concernant les perfs , c'est en 1024x768x32
la synchronisation est désactivé. Essayé les 3 modes de rendu , Dot,Wire,Flat, il y a la gestion de la lumière ambiente.
C'est que des commandes de purebasic, pas de lib, ou autre préfabriqué à la sauce OpenGl ou DirectX :D
Le pure est vraiment puissant ! :D

D'ailleurs tonton, 1 de ces 4 , je viendrais de harceler pour optimiser en asm des calculs matriciels :D

Bye @+

Publié : mer. 13/déc./2006 0:15
par djes
Ici ça tourne bien, quelques ralentissements de ci de là, mais ça va. Tu vas rajouter un tri des faces?

Publié : mer. 13/déc./2006 0:29
par Guimauve
Ici aussi ça tourne bien.

Le FPS :

25-30 en flat
120-128 en dot
40-45 en wire

A+
Guimauve

Publié : mer. 13/déc./2006 6:19
par tmyke
je n'est pu tester que sur mon ATI9700pro et centrino 1.7Ghz (ordi portable)
resultat:

50 fps en wire
160 en dot
30 en flat

:wink: