Results 1 to 6 of 6

Thread: How convert c++ code?

  1. #1

    How convert c++ code?

    Hi all,

    i have a problem, it's possible to convert this c++ code into delphi. Any chance or workaround?

    Code:
    list<Vector2> vList;
    const Vector2 vMin = 1.2f;
    const Vector2 vMax = 8.9f;
     
    list.clear();
    for (float y = vMin.y; y<=vMax.y; y+=1.0f)
    {
        for (float x = vMin.x; x<=vMax.x; x+=1.0f)
        {
        outList.push_back(Vector2(x, y));
        }
    }
    Thanks in advance
    Sesilla

  2. #2

    Thumbs up

    Maybe like this?

    Code:
    var
      x, y: Single;
    const 
      vMin = 1.2;
      vMax = 8.9;
    begin
      x := vMin;
      y := vMin;
      while (x <= vMax) do
      begin
        while (y <= vMax) do
        begin
          //Something here...
          y := y + 1;
        end;
        x := x + 1;
      end;
    
    end;
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3
    Try this:
    Code:
    uses
       Generics.Collections;
       
    var
      outList: TList<Vector2>;
      vMin, vMax: Vector2;
      x, y: Single;
    begin
      outList.Clear();
      
      y := vMin.y;
      x := vMin.x;
      while (y <= vMax.y) do
      begin
        while (x <= vMax.x) do
    	begin
    	  outList.Add(Vector2(x, y));
    	  x := x + 1;
    	end;
        y := y + 1.0;
      end;
    end;
    Works in D2009 and up.

  4. #4
    me too i'd like to convert this code ,seems difficult to do so, especially the procedure SetShaders()

    Code:
    typedef void (*GenFP)(void); // any function ptr type would do
    static GenFP glFP[7];
    const static char* glnames[]={
         "glCreateShader", "glCreateProgram", "glShaderSource", "glCompileShader", 
         "glAttachShader", "glLinkProgram", "glUseProgram"
    };
    
    static void setShaders() {
    int i;
      // 19. April 2007:    "(GenFP) cast" added by benny!weltenkonstrukteur.de
      for (i=0; i<7; i++) glFP[i] = (GenFP)wglGetProcAddress(glnames[i]);
      GLuint v = ((PFNGLCREATESHADERPROC)(glFP[0]))(GL_VERTEX_SHADER);
      GLuint f = ((PFNGLCREATESHADERPROC)(glFP[0]))(GL_FRAGMENT_SHADER);    
      GLuint p = ((PFNGLCREATEPROGRAMPROC)glFP[1])();
      ((PFNGLSHADERSOURCEPROC)glFP[2]) (v, 1, &vsh, NULL);
      ((PFNGLCOMPILESHADERPROC)glFP[3])(v);
      ((PFNGLSHADERSOURCEPROC)glFP[2]) (f, 1, &fsh, NULL);
      ((PFNGLCOMPILESHADERPROC)glFP[3])(f);
      ((PFNGLATTACHSHADERPROC)glFP[4])(p,v);
      ((PFNGLATTACHSHADERPROC)glFP[4])(p,f);
      ((PFNGLLINKPROGRAMPROC)glFP[5])(p);
      ((PFNGLUSEPROGRAMPROC) glFP[6])(p);
    }
    vsh : just an array of char ( contain the vertex shader )
    fsh : .................................................f ragment shader)
    Last edited by virtual; 11-12-2010 at 10:02 PM.

  5. #5
    Ah someone is trying to create 4k's..

    Something like this should work:
    Code:
    const
     glNames: array[0..6] of pchar = ('glCreateShader', 'glCreateProgram', 'glShaderSource', 'glCompileShader', 'glAttachShader', 'glLinkProgram', 'glUseProgram');
    
    var
     glFP: array[0..6] of pointer;
    
    type
     TGLCreateShader = function(Typ: GLenum): GLUint; cdecl;
     TGLCreateProgram = function: GLUint; cdecl;
     TGLShaderSource = function(Shader: GLUint; Count: GLInt; PointerToPchar: Pointer; Len: GLUint): GLUint;
     TGLCompileShader = function(Shader: GLUint): GLUint;
     TGLAttachShader = function(Prog, Shader: GLUint): GLUint;
     TGLLinkProgram = function(Prog: GLUint): GLUint;
     TGLUseProgram = function(Prog: GLUint): GLUint;
    
    procedure setShader;
    var v,f,p: GLUint;
    begin
       for i := 0 to 6 do
          glFP[i] := wglGetProcAddress(glNames[i]);
       
       v := TGLCreateShader(glFP[0])(GL_VERTEX_SHADER);
       f := TGLCreateShader(glFP[0])(GL_FRAGMENT_SHADER);
       p := TGLCreateProgram(glFP[1])();
       TGLShaderSource(glFP[2])(v,1,@vsh,nil);
       TGLCompileShader(glFP[3])(v);
       TGLShaderSource(glFP[2])(f,1,@fsh,nil);
       TGLCompileShader(glFP[3])(f);
       TGLAttachShader(glFP[4])(p,v);
       TGLAttachShader(glFP[4])(p,f);
       TGLLinkProgram(glFP[5])(p);
       TGLUseProgram(glFP[6])(p);
    end;
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6
    JSoftware : thank you
    in fact this is a c++ 1k OGL+shader , with delphi this would be 1~2 kb

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •