Sprite in BCB 4
-
Du meinst einfach ein TImage bewegen? Ja das ist es ja das flackert eben nur wie wild. Gibt es keine möglich keit mit DirectX9 ("relativ" einfach) sprites in Borland C++ einzubauen? DirectX 9 SDK habe ich.
Oder geht das nur in VC++ ?
Kann ich mir nicht vorstellen das das so sehr umständlich in BCB sein soll.
-
Die DX-Libs funktionieren AFAIK nicht mit Borland Compilern, siehe dazu auch FAQ.
Bye, TGGC
-
Forms in Delphi und BCB haben eine (nicht publishedte) Property "DoubleBuffered". Das im Form.Create() auf true setzen und Deine Buttons und Images flackern nicht mehr!
Mit dem BCB und auch mit Delphi kann man auf jeden Fall DX oder GL coden. Allerdings eher im Sinne von Fullscreen oder mit CreateWindow-liken-"pure"-WinAPI-Funktionen ein Fenster erstellen.
Wie man z.B. für einen Editor ein TImage als Rendertarget benutzt konnte ich auch noch nicht herausfinden, konnte mich aus Zeitgründen allerdings auch noch nicht weiter damit beschäftigen. Zumindest haben die Dinger ja ein Property Handle, das einem einen old-sk00l-Windows-DeviceContext liefert. Damit liesse sich ja schon was machen...
Wenn es klappt, bitte Feedback geben!:xmas1:
-
Sgt. Nukem schrieb:
Wie man z.B. für einen Editor ein TImage als Rendertarget benutzt konnte ich auch noch nicht herausfinden, konnte mich aus Zeitgründen allerdings auch noch nicht weiter damit beschäftigen. Zumindest haben die Dinger ja ein Property Handle, das einem einen old-sk00l-Windows-DeviceContext liefert. Damit liesse sich ja schon was machen...
Wenn es klappt, bitte Feedback geben!:xmas1:
Wenn du das wissen willst, musst du nur mal nach "Borland OpenGL" hier im Forum suchen. Dir muesste dann unter anderem dieser Beitrag auffallen:
http://www.c-plusplus.net/forum/viewtopic.php?t=12648&highlight=borland+opengl
Da muesste man nur das gewuenschte Handle einfuegen und fertig.
(_vermute_ ich mal, versucht habe ich es noch nicht)
Das Problem bei einem Image waere nur, dass es von TGraphicControl abgeleitet ist und deshalb kein Handle besitzt.
MfG Aoeke
-
OK, ich habs gerade mit einem Button getestet. Also einfach das Handle des Buttons angegeben und fertig. Hat gefunzt.
-
Aoeke schrieb:
OK, ich habs gerade mit einem Button getestet. Also einfach das Handle des Buttons angegeben und fertig. Hat gefunzt.
Hmmm... hatte jetzt was Zeit und mal mit dem BCB rumprobiert.
So auf Anhieb funzt der Code sowieso net, man mußte da noch ein paar Dinge ändern (Var.Dekl. etc.)...Aber auch danach bekam ich den GL Part nicht ans Laufen, nicht mit dem Fensterhandle.
Aber es wird ja keinerlei Fehlerüberprüfung gemacht, von daher ist es so schwer zu sagen...
Schade, daß quasi NICHTS auf Anhieb klappt...
-
@Aoeke:
Kannst Du mal den Code posten, der z.B. ein gecleartes GL-Fenster zeigt (BCB-Code).
Z.B. mit dem Button oder einem Panel als Fenster-Handle. (D.h. kein neues Fenster aufmachen mit CreateWindowEx etc.)Würde mir sehr helfen!
-
Also das schaut bei mir so aus:
///////////////////////////////////////////////////////////////////////////// // OpenGL Application // // written by Stefan Lobach // // with Borland C++ Builder 5.0 // ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // HEADER Unit1.h // ///////////////////////////////////////////////////////////////////////////// #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <gl\gl.h> #include <gl\glu.h> #include <float.h> #include <own\camera.h> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: TButton *Button1; void __fastcall FormCreate(TObject *Sender); void __fastcall FormDestroy(TObject *Sender); void __fastcall FormResize(TObject *Sender); private: HDC hdc; HGLRC hrc; int PixelFormat; CCamera Cam; // This Is Our Camera, Our Eyes In This World void __fastcall IdleLoop(TObject*, bool&); void __fastcall RenderGLScene(); void __fastcall SetPixelFormatDescriptor(); void __fastcall SetupRC(); public: virtual __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern TForm1 *Form1; //--------------------------------------------------------------------------- #endif ///////////////////////////////////////////////////////////////////////////// // OpenGL Application // // written by Stefan Lobach // // with Borland C++ Builder 5.0 // ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // SOURCE Unit1.cpp // ///////////////////////////////////////////////////////////////////////////// #include <vcl.h> #pragma hdrstop #include "Unit1.h" ///////////////////////////////////////////////////////////////////////////// #pragma resource "*.dfm" TForm1 *Form1; ///////////////////////////////////////////////////////////////////////////// void __fastcall TForm1::SetPixelFormatDescriptor() { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 24, 0,0,0,0,0,0, 0,0, 0,0,0,0,0, 32, 0, 0, PFD_MAIN_PLANE, 0, 0,0,0 }; PixelFormat = ChoosePixelFormat( hdc, &pfd ); SetPixelFormat( hdc, PixelFormat, &pfd ); } ///////////////////////////////////////////////////////////////////////////// void __fastcall TForm1::SetupRC() { glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); // set background color glClear( GL_COLOR_BUFFER_BIT ); // clear the color buffer glClearDepth ( 1.0 ); // depth buffer setup glEnable ( GL_DEPTH_TEST ); // enable depth testing glDepthFunc ( GL_LEQUAL ); // the type of depth test to do glHint ( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); // really nice // perspective calculations glFlush(); // force execution of OpenGL functions } ///////////////////////////////////////////////////////////////////////////// void __fastcall TForm1::RenderGLScene() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // clear the color // and depth buffer glLoadIdentity(); Cam.Look(); // define a viewing transformation static float angle = 0.0f; angle += 0.5f; glColor3f( 0.0f, 0.0f, 1.0f ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glRotatef( angle, 0.0f, 1.0f, 0.0f ); glBegin( GL_QUADS ); glVertex3f( -1.0f, 1.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, 0.0f ); glVertex3f( 1.0f, 1.0f, 0.0f ); glEnd(); } ///////////////////////////////////////////////////////////////////////////// __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Application->OnIdle = IdleLoop; // set OnIdle Event _control87( MCW_EM, MCW_EM ); // don't throw any floating point // exceptions } ///////////////////////////////////////////////////////////////////////////// void __fastcall TForm1::FormCreate(TObject *Sender) { hdc = GetDC( Button1->Handle ); // get the device context SetPixelFormatDescriptor(); // set pixel format hrc = wglCreateContext( hdc ); // set rendering context wglMakeCurrent( hdc, hrc ); // create rendering context SetupRC(); // setup our rendering context // set the camera properties Cam.PositionCamera( 0.0, 1.0, 5.0, // position 0.0, 0.0, 0.0, // view / reference point 0.0, 1.0, 0.0 ); // upvector } ///////////////////////////////////////////////////////////////////////////// void __fastcall TForm1::FormDestroy(TObject *Sender) { ReleaseDC( Handle, hdc ); // release our device context wglMakeCurrent( hdc, NULL ); // free our rendering context wglDeleteContext( hrc ); // delete our rendering context } ///////////////////////////////////////////////////////////////////////////// void __fastcall TForm1::FormResize(TObject *Sender) { GLfloat nRange = 10.0f; // 20 units should be shown GLsizei wid = ClientWidth; // get the wid and the hei of GLsizei hei = ClientHeight; // the available part of the window glMatrixMode( GL_PROJECTION ); // specify which matrix is the // current matrix glLoadIdentity(); // reset the current matrix /* // Set ortho mode if( wid <= hei ) { glOrtho( -nRange, nRange, -nRange * hei / wid, nRange * hei / wid, -nRange, nRange ); } else { // left, right -> number of units on x-axis // top, bottom -> number of units on y-axis // near, far -> number of units on z-axis glOrtho( -nRange * wid / hei, nRange * wid / hei, -nRange, nRange, -nRange, nRange ); } glViewport( 0, 0, wid, hei ); // set the viewport */ ///* GLfloat aspect; // gets the aspect of our window aspect =( GLfloat )wid / hei; // get the aspect of our window // set up a perspective projection matrix gluPerspective( 45.0, // the field of view angle, in // degrees, in the y-direction aspect, // the aspect ratio that determines // the field of view in the x-direction 1.0, // the distance from the viewer to // the near clipping plane // (always positive) 150.0 ); // the distance from the viewer to // the far clipping plane // (always positive) //*/ glMatrixMode( GL_MODELVIEW ); // specify which matrix is the // current matrix glLoadIdentity(); } ///////////////////////////////////////////////////////////////////////////// void __fastcall TForm1::IdleLoop(TObject*, bool& done) { done = false; // keep the loop going RenderGLScene(); // do drawing stuff SwapBuffers( hdc ); // exchange front and back buffer } /////////////////////////////////////////////////////////////////////////////
MfG Aoeke
<edit>Habe ich jetzt einfach mal aus dem Projekt kopiert. Also bei mir laeuft der so. Ist zwar nicht bloss Initialisierung, sondern noch mit Kamera (selbst gemacht, nicht wundern
) und ein drehendes Rechteck, aber sicherlich trotzdem noch gut zu durchschauen..</edit>
-
Aoeke schrieb:
Also das schaut bei mir so aus:
///////////////////////////////////////////////////////////////////////////// // OpenGL Application // // written by Stefan Lobach // // with Borland C++ Builder 5.0 // /////////////////////////////////////////////////////////////////////////////
Hab' zwar jetzt keine Zeit mehr....
.... aber danke für die Antwort!Ging ja mächtig schnell!! :xmas1:
Werd's mir morgen reinpfeifen!! Gut' N8!
-
So, wachgeworden, mal schnell ausprobiert...
(Ist ja auch "morgen"...)
Im Pixelformat hatte ich wohl'n Flüchtigkeitsfehler.
Trotzdem nicht das gewünschte Ergebnis. *wein*
Werd' ich wohl mal alle Routinen auf Fehlerrückgaben umbauen.
Naja, N8 dann wieder... :xmas1: