В общем, попробую сам написать на Си.
' PhotonMapping#ifndef true#define true -1#define false 0 #endifType float As single 'doubleConst As Integer xDimension = 512Const As Integer yDimension = 512Const As Integer nTypes = 2 ' two types of objects sphere and planeConst As Integer MaxPhotons = 200Const As Integer MaxPhotonRefections = 1Const As float PhotonSize = 0.1Const As float gInverseSquared = 1.0 / PhotonSize * PhotonSizeConst As float MilliSeconds = 500Const As float gExposure = 1.0 / (1000 / MilliSeconds)Const As Integer MaxRaytraceRefections = 12#define nSpheres 3 ' number of spheres#define nPlanes 6 ' number of planes (a box)Dim Shared As float RatioDim Shared As Integer gNObjects(1) = {nSpheres,nPlanes&}Dim Shared As float gAmbient = 0Dim Shared As float gOrigin(2)Dim Shared As float gLight(2) = {0,1.0,4} 'x,y,z positionDim Shared As float gSpheres(nSpheres-1,3) = {_ {-1.0,-1.0,4.0, 0.5} , _ { 6.4, 0.0,2.8, 5.0} , _ { 1.0,-1.0,4.0, 0.5}} ' x,y,z, position and radiusDim Shared As float gPlanes(nPlanes-1,1) = {_ {0, 1.5}, _ {0, -1.5}, _ {1, -1.5}, _ {1, 1.5}, _ {2, 5.0}, _ {2, -1.0}}Dim Shared As Integer NumberOfPhotons(1,5)Dim Shared As float gPhotons(nTypes,nPlanes+nSpheres, _ MaxPhotons + MaxPhotons*MaxPhotonRefections, _ 2,2) '3 * x,y,zDim Shared As Integer gIntersectDim Shared As Integer gTypeDim Shared As Integer gIndexDim Shared As float gDist2,gDistDim Shared As float gPoint(2)Function min(a As float ,b As float ) As float If b<a Then Return b Return aEnd FunctionFunction max(a As float ,b As float ) As float If b>a Then Return b Return aEnd FunctionFunction rnd2 As float Return (Rnd-Rnd)End FunctionFunction SquaredDistance(a() As float , _ b() As float , _ d2 As float ) As Integer Dim As float ab = a(0) - b(0) Dim As float d = ab*ab If (d > d2) Then Return false ab = a(1) - b(1) d += ab*ab If (d > d2) Then Return false ab = a(2) - b(2) d += ab*ab If (d > d2) Then Return false gDist2 = d Return trueEnd FunctionSub SurfaceNormal(r() As float , _ typ As Integer, _ idx As Integer, _ HitPoint() As float , _ O() As float ) Dim As float Normal(2),L If (typ = 0) Then Normal(0)=HitPoint(0)-gSpheres(idx,0) Normal(1)=HitPoint(1)-gSpheres(idx,1) Normal(2)=HitPoint(2)-gSpheres(idx,2) Elseif (typ = 1) Then Dim As Integer axis = gPlanes(idx,0) Normal(axis) = O(axis) - gPlanes(idx,1) Else 'beep End If l=Normal(0)*Normal(0) _ +Normal(1)*Normal(1) _ +Normal(2)*Normal(2) If l Then l=1/Sqr(l) r(0)=Normal(0)*l r(1)=Normal(1)*l r(2)=Normal(2)*lEnd SubSub Mirror2(Ret() As float, _ Direction() As float, _ HitPoint() As float, _ Normale() As float) Dim As float L HitPoint(0)+=Direction(0)*-0.1 HitPoint(1)+=Direction(1)*-0.1 HitPoint(2)+=Direction(2)*-0.1 L = Normale(0)*Direction(0) _ + Normale(1)*Direction(1) _ + Normale(2)*Direction(2) L*=-2 Ret(0)=Direction(0)+L*Normale(0) Ret(1)=Direction(1)+L*Normale(1) Ret(2)=Direction(2)+L*Normale(2)End SubSub MirrorVec(Ret() As float ,_ Direction() As float , _ Origin() As float ) Dim As float L,Normale(2) SurfaceNormal(Normale(),gType, gIndex, gPoint(), Origin()) gPoint(0)+=Direction(0)*-0.1 gPoint(1)+=Direction(1)*-0.1 gPoint(2)+=Direction(2)*-0.1 L = Normale(0)*Direction(0) _ + Normale(1)*Direction(1) _ + Normale(2)*Direction(2) L*=-2 Ret(0)=Direction(0)+L*Normale(0) Ret(1)=Direction(1)+L*Normale(1) Ret(2)=Direction(2)+L*Normale(2)End Sub'' Raytracing'Sub Raytrace(RayDirection() As float ,RayOrigin() As float ) gIntersect = false gDist = 999999.9 If gNObjects(1)>0 Then For idx As Integer =0 To gNObjects(1)-1 Dim As Integer axis = gPlanes(idx,0) If RayDirection(axis)<>0 Then Dim As float l = (gPlanes(idx,1) - RayOrigin(axis)) / RayDirection(axis) If (l>0) And (l<gDist) Then gType = 1 gIndex = idx gDist = l gIntersect = true End If End If Next End If If gNObjects(0)>0 Then Dim As float SphereDirection(2) Dim As float A = RayDirection(0)*RayDirection(0) _ + RayDirection(1)*RayDirection(1) _ + RayDirection(2)*RayDirection(2) A+=A For idx As Integer =0 To gNObjects(0)-1 SphereDirection(0)=RayOrigin(0)-gSpheres(idx,0) SphereDirection(1)=RayOrigin(1)-gSpheres(idx,1) SphereDirection(2)=RayOrigin(2)-gSpheres(idx,2) Dim As float R = gSpheres(idx,3)*gSpheres(idx,3) Dim As float B = SphereDirection(0)*RayDirection(0) _ + SphereDirection(1)*RayDirection(1) _ + SphereDirection(2)*RayDirection(2) B+=B Dim As float C = SphereDirection(0)*SphereDirection(0) _ + SphereDirection(1)*SphereDirection(1) _ + SphereDirection(2)*SphereDirection(2) C-=R Dim As float D = B*B - 2*A*C If (D>0.0) Then Dim As float sign = iif(C < -0.0001,1.0,-1.0) Dim As float l = (-B + sign*Sqr(D))/A If (l>0.0) And (l<gDist) Then gType = 0 gIndex = idx gDist = l gIntersect = true End If End If Next End IfEnd SubSub AbsorbColor(ret() As float , _ rgbIn() As float , _ r As float ,g As float ,b As float ) Dim As float rgbOut(2)={r,g,b} For c As Integer =0 To 2 If rgbOut(c)<rgbIn(c) Then ret(c)=rgbOut(c) Else ret(c)=rgbIn(c) End If NextEnd SubSub GetColor(r() As float , _ rgbIn() As float , _ typ As Integer, _ idx As Integer) If (typ=0) Then ' spheres If idx=0 Then AbsorbColor(r(),rgbIn(), 0.0,0.0,0.0) Elseif idx=1 Then AbsorbColor(r(),rgbIn(), 0.0,0.0,0.0) elseif idx=2 then AbsorbColor(r(),rgbIn(), 0.2,0.2,0. End If Elseif (typ=1) Then ' planes If idx=0 Then AbsorbColor(r(),rgbIn(), 0.1, 0.8, 0.1) ' right Elseif idx=1 Then AbsorbColor(r(),rgbIn(), 0.8, 0.1, 0.1) ' left Elseif idx=2 Then AbsorbColor(r(),rgbIn(), 0.5, 0.5, 0.0) ' floor Elseif idx=3 Then AbsorbColor(r(),rgbIn(), 0.2, 0.2, 0.2) ' ceil Elseif idx=4 Then AbsorbColor(r(),rgbIn(), 0.0, 0.0, 0.0) ' front Elseif idx=5 Then AbsorbColor(r(),rgbIn(), 0.0, 0.0, 0.0) ' behind camera End If End IfEnd Sub'' Photon Mapping'Sub GatherPhotons(energy() As float , _ HitPoint() As float , _ typ As Integer, _ idx As Integer) Dim As float N(2) Dim As float v(2) Dim As float weight Dim As float frgb(2) SurfaceNormal(N(), typ, idx, HitPoint(), gOrigin()) For i As Integer = 0 To NumberOfPhotons(typ,idx)-1 ' photon location v(0)=gPhotons(typ,idx,i,0,0) v(1)=gPhotons(typ,idx,i,0,1) v(2)=gPhotons(typ,idx,i,0,2) ' in the near of an active photon ? If (SquaredDistance(HitPoint(),v(),gInverseSquared)) Then ' photon direction Dim As float cosin = N(0)*gPhotons(typ,idx,i,1,0) _ + N(1)*gPhotons(typ,idx,i,1,1) _ + N(2)*gPhotons(typ,idx,i,1,2) weight = max(0.0, -cosin) if weight then weight *= (1.0 - sqr(gDist2)) * gExposure if weight then ' photon energy frgb(0)+=gPhotons(typ,idx,i,2,0)*weight frgb(1)+=gPhotons(typ,idx,i,2,1)*weight frgb(2)+=gPhotons(typ,idx,i,2,2)*weight end if end if End If Next For j As Integer=0 To 2 energy(j)=max(0,min(1,frgb(j) ) ) NextEnd SubSub StorePhoton(typ As Integer, _ idx As Integer, _ l() As float ,_ d() As float , _ e() As float ) Dim As Integer Photon=NumberOfPhotons(typ,idx) For i As Integer=0 To 2 gPhotons(typ,idx,Photon,0,i) = l(i) ' Location gPhotons(typ,idx,Photon,1,i) = d(i) ' Direction gPhotons(typ,idx,Photon,2,i) = e(i) ' Energy Next NumberOfPhotons(typ,idx)=Photon+1End SubSub ShadowPhoton(RayDirection() As float ) static As float BumpedPoint(2) static As float ShadowPoint(2) Static As float ShadowEnerg(2) = {-0.2,-0.2,-0.2} Dim As float OldPoint(2) = {gPoint(0), gPoint(1),gPoint(2)} Dim As Integer OldType = gType Dim As Integer OldIndex = gIndex Dim As float OldDist = gDist BumpedPoint(0)=gPoint(0)+RayDirection(0)*0.000001 BumpedPoint(1)=gPoint(1)+RayDirection(1)*0.000001 BumpedPoint(2)=gPoint(2)+RayDirection(2)*0.000001 Raytrace(RayDirection(), BumpedPoint()) ShadowPoint(0)=BumpedPoint(0)+RayDirection(0)*gDist ShadowPoint(1)=BumpedPoint(1)+RayDirection(1)*gDist ShadowPoint(2)=BumpedPoint(2)+RayDirection(2)*gDist StorePhoton(gType, gIndex, ShadowPoint(), RayDirection(), ShadowEnerg()) gPoint(0) = OldPoint(0) gPoint(1) = OldPoint(1) gPoint(2) = OldPoint(2) gType = OldType gIndex = OldIndex gDist = OldDistEnd SubSub EmitPhotons randomize 1 'timer dim As float PhotonEnergy(2) dim As float PhotonDirection(2) dim As float PhotonOrigin(2),l For typ As Integer = 0 To nTypes-1 For idx As Integer = 0 To gNObjects(typ)-1 NumberOfPhotons(typ,idx) = 0 Next Next For i As Integer = 0 To MaxPhotons-1 Dim As Integer Reflection = 0 ' random photon Energy PhotonEnergy(0)=rnd PhotonEnergy(1)=rnd PhotonEnergy(2)=rnd#if 0 ' normalize energy l = PhotonEnergy(0)*PhotonEnergy(0) _ + PhotonEnergy(1)*PhotonEnergy(1) _ + PhotonEnergy(2)*PhotonEnergy(2) if l then l=1.0/sqr(l) PhotonEnergy(0)*=l PhotonEnergy(1)*=l PhotonEnergy(2)*=l end if#endif ' radom photon Direction PhotonDirection(0)= rnd2 PhotonDirection(1)= rnd2*2 PhotonDirection(2)= rnd2#if 0 ' normalize direction l = PhotonDirection(0)*PhotonDirection(0) _ + PhotonDirection(1)*PhotonDirection(1) _ + PhotonDirection(2)*PhotonDirection(2) if l then l=1.0/sqr(l) PhotonDirection(0)*=l PhotonDirection(1)*=l PhotonDirection(2)*=l end if#endif ' photon position origin from light PhotonOrigin(0)=gLight(0) PhotonOrigin(1)=gLight(1) PhotonOrigin(2)=gLight(2) Raytrace(PhotonDirection(), PhotonOrigin()) While (gIntersect<>0) And (Reflection < MaxPhotonRefections) Reflection+=1 gPoint(0)=PhotonOrigin(0)+PhotonDirection(0)*gDist gPoint(1)=PhotonOrigin(1)+PhotonDirection(1)*gDist gPoint(2)=PhotonOrigin(2)+PhotonDirection(2)*gDist GetColor(PhotonEnergy(),PhotonEnergy(),gType,gIndex)#if 0 Dim As float l=1.0/Reflection PhotonEnergy(0)*=l PhotonEnergy(1)*=l PhotonEnergy(2)*=l#endif StorePhoton(gType, gIndex, gPoint(), PhotonDirection(),PhotonEnergy()) ShadowPhoton(PhotonDirection()) MirrorVec(PhotonDirection(),PhotonDirection(),PhotonOrigin()) Raytrace(PhotonDirection(), gPoint()) PhotonOrigin(0)=gPoint(0) PhotonOrigin(1)=gPoint(1) PhotonOrigin(2)=gPoint(2) Wend NextEnd SubSub GetPixelColor(PixelRGB() As float , _ x As float ,y As float , z As float=1) Dim As float RayDirection(2) = {x,y,z} Raytrace(RayDirection(), gOrigin()) If (gIntersect) Then gPoint(0)=gOrigin(0)+RayDirection(0)*gDist gPoint(1)=gOrigin(1)+RayDirection(1)*gDist gPoint(2)=gOrigin(2)+RayDirection(2)*gDist GatherPhotons(PixelRGB(),gPoint(),gType,gIndex) ' If gType=0 or gIndex>3 Then Dim As Integer nDivs=0,nReflection=0 Dim As float MirrorsRGB(2) While ((gType=0 And gIndex<2) Or gIndex>3) And gIntersect And _ (nReflection<MaxRaytraceRefections) nReflection+=1 MirrorVec(RayDirection(),RayDirection(),gOrigin()) Raytrace(RayDirection(), gPoint()) If (gIntersect) Then Dim As float MirRGB(2) nDivs+=1 gPoint(0)+=RayDirection(0)*gDist gPoint(1)+=RayDirection(1)*gDist gPoint(2)+=RayDirection(2)*gDist GatherPhotons(MirRGB(),gPoint(),gType,gIndex) MirrorsRGB(0)+=MirRGB(0) MirrorsRGB(1)+=MirRGB(1) MirrorsRGB(2)+=MirRGB(2) End If Wend If nDivs>0 Then MirrorsRGB(0)/=nDivs MirrorsRGB(1)/=nDivs MirrorsRGB(2)/=nDivs PixelRGB(0)=PixelRGB(0)*0.25+MirrorsRGB(0)*0.75 PixelRGB(1)=PixelRGB(1)*0.25+MirrorsRGB(1)*0.75 PixelRGB(2)=PixelRGB(2)*0.25+MirrorsRGB(2)*0.75 End If 'End If Else PixelRGB(0)=1 ' !!! debug only !!! PixelRGB(1)=0 PixelRGB(2)=1 End IfEnd SubSub Render Dim As Integer h,m,s,l,t dim as float b(2),x,y Dim As Double t1=Timer WindowTitle " PhotonMapper rendering ..." for t =0 to yDimension-1 Y = -(t/yDimension - 0.5) screenlock for l =0 to xDimension-1 X = (l/xDimension - 0.5)*Ratio GetPixelColor(b(),x,y) pset (l,t),rgb(b(0)*255,b(1)*255,b(2)*255) next screenunlock next s=timer-t1:h=s\3600:s-=h*3600:m=s\60:s-=m*60 WindowTitle "PhotonMapper done " & h & ":" & m & ":" & sEnd Sub'' main'Ratio= iif(xDimension>yDimension, _ xDimension/yDimension, _ yDimension/xDimension)Randomize TimerScreenRes xDimension,yDimension,24EmitPhotonsRender'Bsave "PhotonMapper.bmp",0Sleep
#include <graphics.h>#include <stdio.h>int main( void){ //---------- Инициализация графики ----------// int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver,&gmode,""); //---------- Конец инициализации -----------// for (int i = 0; i < 1000000; i++) { putpixel(rand()%640,rand()%500,rand()%0xFFFF); } printf("End");return 0;}
Да я вполне согласен, что код FreеBasic может уступать коду С++, хотя компилятор gcc у обоих один и тот же Вообще речь не об этом... мне ж тоже интересно врубиться в Си.
Я не вижу, что у freebasic в линуксе компилятор gcc
Не думаю, что ты начал с простого. Вернее, может, и с простого, но закончится это ещё одной сторонней либой по рисованию окон. Одно дело пиксели покрасить, а другое дело, файловый диалог вызвать, чтобы выбрать файл для рендера, и пошло поехало...
>> Кстати, в том примере с пикселями у меня используется DirectX, потому так шустро... у тебя по идее это должен быть X11... наверное даже не x11, а opengl ...
' Интеграция OpenGL#INCLUDE Once "GL/gl.bi"'#INCLUDE Once "GL/glu.bi"' Определение констант, которые важны для экранаConst scrnX = 800Const scrnY = 600Const depth = 32Const fullscreen = &h0 ' Полноэкранный режим ( &h0 = обычный, &h1 = полноэкранный )Dim As String driver: Dim As Integer i: Dim As Double startScreenres scrnX,scrnY,depth,,&h2 Or fullscreen '&h2 = режим OpenGLScreenInfo ,,,,,, driver' Конфигурация OpenGLglMatrixMode(GL_PROJECTION) ' Определение матрицыglLoadIdentityglViewport(0,0,scrnX,scrnY) ' Установка оси координатglOrtho(0,scrnX,scrnY,0,-128,128)glMatrixMode(GL_MODELVIEW) ' Отключить вывод невидимых частейglEnable(GL_CULL_FACE)glCullFace(GL_BACK)'glEnable GL_TEXTURE_2D ' Включение текстур'glLoadIdentity'glEnable(GL_DEPTH_TEST) ' Тест глубины'glDepthFunc(GL_LESS)'glEnable(GL_ALPHA_TEST) ' Тест Альфа'glAlphaFunc(GL_GREATER, 0.1)Do glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT 'очищаем экран ' !! здесь различные команды !! start = Timer 'glPointSize (rnd*10) 'размер точки glBegin (GL_POINTS) For i = 1 To 1000000 glColor3f (Rnd,Rnd,Rnd) ' RGB цвет в формате 0 до 1 glVertex2f (Rnd*scrnX, Rnd*scrnY) ' рисуем точку Next i glEnd WindowTitle "Driver: "+driver+" Time: "+Str(Timer-start) ' !! здесь различные команды !! glFlush ' Обработка команд FlipLoop Until MultiKey(&h01) ' Выход из цикла при нажатии Esc
SDL - либа слабая. Я не видел ни скроллеров в ней, ни сплиттеров. Её используют многие для вывода картинки рендера, но, у меня виды на будущее.Я выбрал либу с большИм числом виджетов. В прок! Чтоб не переписывать потом, и не изобретать велосипед в поисках чего-то типа graphics.h. К фоксу я нашёл либу, использующую векторную графику Cairo, с помощью которой можно крутилки красивые нарисовать, как это делает GTK.
Samovar, ты мне объясни, почему для теста ты выбрал перерисовку пикселов?Почему ты не взял просто какое-нибудь математическое действие, выполняемое миллион раз?Дело в том, что я своей бестолковкой сразу связал перерисовку пикселов с процессом, который рано или поздно востребуется в рендере.
Посему поэтому сначала необходимо безо всяких планов на будущее тупо разобраться с алгоритмами рэйтрэйсинга и понять: как достигается скорость и как достигается экономичность на практике.
#!BPY"""Name: 'Objective-C Header (.h)'Blender: 244Group: 'Export'Tooltip: 'Exports .h file for use with OpenGL ES - Modified by Jody McAdams (jmcadams@digipen.edu). Original from iphonedevelopment.blogspot.com'"""import Blenderfrom Blender import *import bpyimport bpyimport os def write_obj(filepath): out = file(filepath, 'w') sce = bpy.data.scenes.active ob = sce.objects.active mesh = Mesh.New() mesh.getFromObject(ob.name) editmode = Window.EditMode() if editmode: Window.EditMode(0) has_quads = False for f in mesh.faces: if len(f) == 4: has_quads = True break if has_quads: oldmode = Mesh.Mode() Mesh.Mode(Mesh.SelectModes['FACE']) mesh.sel = True tempob = sce.objects.new(mesh) mesh.quadToTriangle(0) # more=0 shortest length oldmode = Mesh.Mode(oldmode) sce.objects.unlink(tempob) Mesh.Mode(oldmode) objectname = ob.getData(True) basename = objectname.capitalize() out.write('#import "GraphicsTypes.h"\n\n\n') if (mesh.faceUV): out.write('static const TexturedVertexData3D %sVertexData[] = {\n' % basename) for face in mesh.faces: for (vert, uvert) in zip(face.verts, face.uv): out.write('\t{/*v:*/{%f, %f, %f}, ' % (vert.co.x, vert.co.z, -vert.co.y) ) out.write('/*n:*/{%f, %f, %f}, ' % (vert.no.x, vert.no.z, -vert.no.y)) out.write('/*t:*/{%f, %f}' % ( uvert.x, 1.0-uvert.y ) ) out.write('},\n') out.write('};\n\n') elif (mesh.vertexColors): out.write('static const ColoredVertexData3D %sVertexData[] = {\n' % basename) for face in mesh.faces: for (vert, color) in zip(face.verts, face.col): out.write('\t{/*v:*/{%f, %f, %f}, ' % (vert.co.x, vert.co.z, -vert.co.y) ) out.write('/*n:*/{%f, %f, %f}, ' % (vert.no.x, vert.no.z, -vert.no.y)) out.write('/*c:*/{%f, %f, %f, %f}' % ( color.r / 255.0, color.g / 255.0, color.b / 255.0, color.a / 255.0) ) out.write('},\n') out.write('};\n\n') else: out.write out.write('static const VertexData3D %sVertexData[] = {\n' % basename) for face in mesh.faces: for vert in face.verts: out.write('\t{/*v:*/{%f, %f, %f}, ' % (vert.co.x, vert.co.z, -vert.co.y) ) out.write('/*n:*/{%f, %f, %f} ' % (vert.no.x, vert.no.z, -vert.no.y)) out.write('},\n') out.write('};\n\n') if editmode: Window.EditMode(1) out.write('#define k%sNumberOfVertices\t%i\n' % (basename, len(mesh.faces) * 3) ) out.write('// Drawing Code:\n') out.write('// glEnableClientState(GL_VERTEX_ARRAY);\n') if (mesh.faceUV): out.write('// glEnableClientState(GL_TEXTURE_COORD_ARRAY);\n') elif (mesh.vertexColors): out.write('// glEnableClientState(GL_COLOR_ARRAY);\n') out.write('// glEnable(GL_COLOR_MATERIAL)\n') out.write('// glEnableClientState(GL_NORMAL_ARRAY);\n') out.write('// glVertexPointer(3, GL_FLOAT, sizeof(') if (mesh.faceUV): out.write('TexturedVertexData3D') elif (mesh.vertexColors): out.write('ColoredVertexData3D') else: out.write('VertexData3D') out.write('), &%sVertexData[0].vertex);\n' % basename) out.write('// glNormalPointer(GL_FLOAT, sizeof(') if (mesh.faceUV): out.write('TexturedVertexData3D') elif (mesh.vertexColors): out.write('ColoredVertexData3D') else: out.write('VertexData3D') out.write('), &%sVertexData[0].normal);\n' % basename) if (mesh.faceUV): out.write('// glTexCoordPointer(2, GL_FLOAT, sizeof(TexturedVertexData3D), &%sVertexData[0].texCoord);\n' % basename) elif (mesh.vertexColors): out.write('// glColorPointer(4, GL_FLOAT, sizeof(ColoredVertexData3D), &%sVertexData[0].color);\n' % basename) out.write('// glDrawArrays(GL_TRIANGLES, 0, k%sNumberOfVertices);\n' % basename) out.write('// glDisableClientState(GL_VERTEX_ARRAY);\n') if (mesh.faceUV): out.write('// glDisableClientState(GL_TEXTURE_COORD_ARRAY);\n') elif (mesh.vertexColors): out.write('// glDisableClientState(GL_NORMAL_ARRAY);\n') out.write('// glDisable(GL_COLOR_MATERIAL);\n') out.write('// glDisableClientState(GL_NORMAL_ARRAY);\n\n\n') out.close()filename = os.path.splitext(Blender.Get('filename'))[0]Blender.Window.FileSelector(write_obj, "Export", '%s.h' % filename)
///////////////////////////////////////////////////////////////////////////// 00.h - Renderfunctions//// This file was created by the OpenGL-Export-Script for Blender.//// Export-Time: 03.08.2016, 02:21:13//// Script written by Michael Gantenbrinker.///////////////////////////////////////////////////////////////////////////#ifndef __00_H__#define __00_H__/////////////////////////////////////////////////////////////////////////// DEFINES#define NUM_MESHES 1#define NUM_LIGHTS 0/////////////////////////////////////////////////////////////////////////// CONSTANTS// Vertex-Array for each Meshconst float fVertices_1[8][3] = { {1.000000f, 1.000000f, -1.000000f}, {1.000000f, -1.000000f, -1.000000f}, {-1.000000f, -1.000000f, -1.000000f}, {-1.000000f, 1.000000f, -1.000000f}, {1.000000f, 0.999999f, 1.000000f}, {0.999999f, -1.000001f, 1.000000f}, {-1.000000f, -1.000000f, 1.000000f}, {-1.000000f, 1.000000f, 1.000000f} };// Normal-Array for each Meshconst float fNormals_1[8][3] = { {0.577349f, 0.577349f, -0.577349f}, {0.577349f, -0.577349f, -0.577349f}, {-0.577349f, -0.577349f, -0.577349f}, {-0.577349f, 0.577349f, -0.577349f}, {0.577349f, 0.577349f, 0.577349f}, {0.577349f, -0.577349f, 0.577349f}, {-0.577349f, -0.577349f, 0.577349f}, {-0.577349f, 0.577349f, 0.577349f} };// Triangle-Indices for each Mesh// Quad-Indices for each Meshconst unsigned long ulQuadIndices_1[6][4] = { {0, 1, 2, 3}, {4, 7, 6, 5}, {0, 4, 5, 1}, {1, 5, 6, 2}, {2, 6, 7, 3}, {4, 0, 3, 7} };// Array with Vertex-Array-Pointersconst float* pVertexPointers[] = {&fVertices_1[0][0]};// Array with Normal-Array-Pointersconst float* pNormalPointers[] = {&fNormals_1[0][0]};// Array with TriangleIndex-Array-Pointersconst unsigned long* pTriangleIndexPointers[] = {0};// Array with QuadIndex-Array-Pointersconst unsigned long* pQuadIndexPointers[] = {&ulQuadIndices_1[0][0]};// Array with Vertex-Array-Lengthsconst unsigned long ulVertexLengths[] = {8};// Array with TriangleIndex-Array-Lengthsconst unsigned long ulTriangleIndexLengths[] = {0};// Array with QuadIndex-Array-Lengthsconst unsigned long ulQuadIndexLengths[] = {6};void Init(){}void Render(int iWidth = 1024, int iHeight = 768){ // Setup Projektion-Matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); double dAspectRatio = (double)iWidth / (double)iHeight; gluPerspective(45.0f, dAspectRatio, 1.0f, 100.0f); glViewport(0, 0, iWidth, iHeight); gluLookAt(5.0f, 5.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); // Setup Lights float lPos[] = {5.0f, 5.0f, 5.0f, 1.0f}; float lDir[] = {-0.707f, -0.707f, -0.707f}; glLightfv(GL_LIGHT0, GL_AMBIENT, StdColor_White); glLightfv(GL_LIGHT0, GL_DIFFUSE, StdColor_BrightGrey); glLightfv(GL_LIGHT0, GL_SPECULAR, StdColor_White); glLightfv(GL_LIGHT0, GL_POSITION, lPos); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lDir); glLightf (GL_LIGHT0, GL_SPOT_CUTOFF, 180.f); glLightf (GL_LIGHT0, GL_SPOT_EXPONENT, 1.0f); glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f); glLightf (GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.6f); glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.06f); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // Setup Scene-Content glMatrixMode(GL_MODELVIEW); glLoadIdentity(); float* fVertices = 0; float* fNormals = 0; unsigned long* ulTriangleIndices = 0; unsigned long* ulQuadIndices = 0; unsigned long* ulPtr = 0; for(int i = 0; i < NUM_MESHES; i++) { fVertices = (float*)pVertexPointers[i]; fNormals = (float*)pNormalPointers[i]; ulTriangleIndices = (unsigned long*)pTriangleIndexPointers[i]; ulQuadIndices = (unsigned long*)pQuadIndexPointers[i]; if(ulTriangleIndices) { glBegin(GL_TRIANGLES); unsigned long t = 0; while(t < ulTriangleIndexLengths[i]*3) { ulPtr = &ulTriangleIndices[t]; glNormal3fv(&fNormals[ulPtr[0]*3]); glVertex3fv(&fVertices[ulPtr[0]*3]); glNormal3fv(&fNormals[ulPtr[1]*3]); glVertex3fv(&fVertices[ulPtr[1]*3]); glNormal3fv(&fNormals[ulPtr[2]*3]); glVertex3fv(&fVertices[ulPtr[2]*3]); t += 3; } glEnd(); } if(ulQuadIndices) { glBegin(GL_QUADS); unsigned long q = 0; while(q < ulQuadIndexLengths[i]*4) { ulPtr = &ulQuadIndices[q]; glNormal3fv(&fNormals[ulPtr[0]*3]); glVertex3fv(&fVertices[ulPtr[0]*3]); glNormal3fv(&fNormals[ulPtr[1]*3]); glVertex3fv(&fVertices[ulPtr[1]*3]); glNormal3fv(&fNormals[ulPtr[2]*3]); glVertex3fv(&fVertices[ulPtr[2]*3]); glNormal3fv(&fNormals[ulPtr[3]*3]); glVertex3fv(&fVertices[ulPtr[3]*3]); q += 4; } glEnd(); } }}#endif /* __00_H__ */