News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Rainbow text with GdipDrawString issue

Started by guga, November 24, 2020, 04:36:09 PM

Previous topic - Next topic

jj2007

Quote from: caballero on November 25, 2020, 09:08:18 PM
Some time ago, I did this text effect: text with dynamic plasma. Pure and brute GDI  :thumbsup:

Doesn't compile with VC, Gcc and PellesC. I thought C was a standard?

avcaballero

If you added TinyC to that list, you would have found the solution  :thumbsup:. The change that must be made so that it compiles in your list is very small and I leave it as an exercise.

Vortex

Trying to compile with tcc :

C:\tcc>tcc -version
tcc version 0.9.27 (x86_64 Windows)

C:\tcc>tcc PlasmaWC03.c
PlasmaWC03.c:63: error: cannot cast 'struct <anonymous>' to 'int'

avcaballero

The code that I had put in the zip by mistake corresponded to another demo, I suppose it can be considered an extra  :bgrin:. The compiling error is due to the same, we have already talked about it in this forum. You cannot associate a structure, such as the palette, to an integer, such as the video buffer. The new version of TinyC no longer allows it, so I continue using the old one. I attach the code that should compile in any type of compiler.

jj2007

Quote from: caballero on November 29, 2020, 10:14:30 PMI attach the code that should compile in any type of compiler.

Gcc:
Tmp.cpp:73:43: error: invalid conversion from 'HGDIOBJ {aka void*}' to 'HFONT' [-fpermissive]
   hOFont = SelectObject (bufLogoDC, hNFont);


PellesC:
#### COMPILING PlasmaWC02b.c ####
Tmp_file.c(63): warning #2116: Local 'hPenOld' is used without being initialized.
Tmp_file.c(93): warning #2215: Conversion from 'int' to 'unsigned char'; possible loss of data or unexpected result.
Tmp_file.c(93): warning #2215: Conversion from 'int' to 'unsigned char'; possible loss of data or unexpected result.
Tmp_file.c(93): warning #2215: Conversion from 'int' to 'unsigned char'; possible loss of data or unexpected result.
Tmp_file.c(184): warning #2229: Local 'hMainDIB' is potentially used without being initialized.
Tmp_file.c(184): warning #2229: Local 'hOldDIB' is potentially used without being initialized.
Tmp_file.c(240): warning #2805: Possible violation of strict-aliasing rules.
Tmp_file.c(226): warning #2118: Parameter 'szCmdLine' is not referenced.
Tmp_file.c(225): warning #2118: Parameter 'hPrevInstance' is not referenced.

#### LINKING PlasmaWC02b.obj sub Windows with kernel32 user32       ####
POLINK: error: Unresolved external symbol '__imp__CreateCompatibleDC@4' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__CreateDIBSection@24' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__SelectObject@8' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__SetBkMode@8' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__SetTextColor@8' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__DeleteDC@4' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__DeleteObject@4' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__BitBlt@36' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__CreateSolidBrush@4' - referenced from 'PlasmaWC02b.obj'.
POLINK: error: Unresolved external symbol '__imp__CreateFontA@56' - referenced from 'PlasmaWC02b.obj'.
POLINK: fatal error: 10 unresolved external(s).

LINK ERROR

avcaballero

They seem like conversion problems that will need some casting or revising the functions I've used. I don't have time to check it now, so ...

jj2007

Quote from: caballero on November 29, 2020, 10:14:30 PMcode that should compile in any type of compiler as long as its name contains the word "tiny"

avcaballero

 :toothy:

I don't like the restrictions of the bigger compilers, that's why I use TinyC (besides that it produces the executables as small as an assembler.). This code only needs some castings to work in the rest. Unfortunately I don't have time to look at it now.

guga

Quote from: jj2007 on November 29, 2020, 11:29:26 PM
Quote from: caballero on November 29, 2020, 10:14:30 PMcode that should compile in any type of compiler as long as its name contains the word "tiny"

Hi JJ.

Do you think that such routines i´m making can be useful for you ? I mean, since you uses gdi+ in masmbasic, maybe a dll containing those  functions can be of some help. The only thing i didn´t do yet was creating specific functions for encoding/decoding webp files, that´s why i´m using libwebp from google (that uses vcruntime140.dll, btw)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

TimoVJL

Quote from: caballero on November 29, 2020, 11:40:52 PM
:toothy:

I don't like the restrictions of the bigger compilers, that's why I use TinyC (besides that it produces the executables as small as an assembler.). This code only needs some castings to work in the rest. Unfortunately I don't have time to look at it now.
        //*(pMainDIB + p) = (miPaleta[m].Rojo<<16)|(miPaleta[m].Verde<<8)|miPaleta[m].Azul;
*(pMainDIB + p) = *(DWORD*)&miPaleta[m];
TinyC isn't an optimizing C compiler.
With PellesC v10, 9 KB
May the source be with you

guga

JJ, I was going to answer, but Timo did it 1st :biggrin: :biggrin: :biggrin:

Anyway, here is attached the converted routines of caballero in asm listing using https://godbolt.org,  online compiler. It won´t assemble in ml.exe, but it can be converted to masm by hand :)  (The logic is not hard to understand when reading the code flow from godbolt) - Or... you can do the same with Timo using Ollydbg

Routines converted:


#include <math.h>

#define cdXPos          128
#define cdYPos          128
#define cdXSize         960
#define cdYSize         600
#define cdColFondo      0        // COLOR_BTNFACE + 1
#define cdVBarTipo      0
#define cdVBtnTipo      WS_VISIBLE+WS_SYSMENU+WS_MINIMIZEBOX
#define cdMainIcon      100
#define cdIdTimer       1
#define cdDosPI         6.283185307179586476925286766559
#define cdFSize         140
#define PI128           0.02454369260617025967548940143187

int               waves[4][2];
double            sins1[360*6], sins2[360*6], sins3[360*6], sins4[360*6];
double            coss1[360*6], coss2[360*6], coss3[360*6], coss4[360*6];
int               f = 0, s1off = 0, s2off = 0, s3off = 0;
int               c1off = 0, c2off = 0, c3off = 0, coloff = 0;

int           hLogoDIB = 0;
int              *pMainDIB = 0, *pLogoDIB = 0;
unsigned char     mtImagen[cdXSize*cdYSize], mtLogo [cdXSize*cdYSize];

struct  stPaleta {
  unsigned char   Azul;
  unsigned char   Verde;
  unsigned char   Rojo;
  unsigned char   Alfa;
} miPaleta[256];


void CreaImagen (void) {
  int           i;
  for (i = 0; i < cdXSize*cdYSize; i++)
    mtImagen[i] = (unsigned char) *(pLogoDIB+i);


void pal (int col, int r, int g, int b) {
  miPaleta[col].Rojo = r; miPaleta[col].Verde = g; miPaleta[col].Azul = b;
}

void grad (int col1, double r1, double g1, double b1,
           int col2, double r2, double g2, double b2) {
  int col, cols;
  cols = col2 - col1 + 1;
  double rstep, gstep, bstep, r, g, b;
  rstep = (double) ((r2 - r1 + 1) / cols);
  gstep = (double) ((g2 - g1 + 1) / cols);
  bstep = (double) ((b2 - b1 + 1) / cols);
  r = r1;
  g = g1;
  b = b1;
  for (col = col1; col <= col2; col++) {
    r += rstep;
    g += gstep;
    b += bstep;
    if (r > 255) r = 255;
    if (r < 0 ) r = 0 ;
    if (g > 255) g = 255;
    if (g < 0 ) g = 0 ;
    if (b > 255) b = 255;
    if (b < 0 ) b = 0 ;
    pal (col, (int)r, (int)g, (int)b);
  }
}

void makePlasma (void) {
  int i, r, g, b, r1, g1, b1, r2, g2, b2;
  r1 = r = rand()&255; g1 = g = rand()&255; b1 = b = rand()&255;
  for (i = 0; i <= 3; i++) {
    r2 = rand()&255; g2 = rand()&255; b2 = rand()&255;
    grad (64 * i, r, g, b, 64 * i + 63, r2, g2, b2);
    r = r2; g = g2; b = b2;
  }
  grad (64 * 3, r, g, b, 255, r1, g1, b1);
  for (i = 0; i < 3; i++) {
    waves[i][0] = rand()&255;
    waves[i][1] = 360 + rand()%180;
  }
  for (i = 0; i <= 360*6; i++) {
    sins1[i] = (double) ((double) waves[0][0] * sin((double) i / waves[0][1] * cdDosPI));
    sins2[i] = (double) ((double) waves[1][0] * sin((double) i / waves[1][1] * cdDosPI));
    sins3[i] = (double) ((double) waves[2][0] * sin((double) i / waves[2][1] * cdDosPI));
    coss1[i] = (double) ((double) waves[0][0] * cos((double) i / waves[0][1] * cdDosPI));
    coss2[i] = (double) ((double) waves[1][0] * cos((double) i / waves[1][1] * cdDosPI));
    coss3[i] = (double) ((double) waves[2][0] * cos((double) i / waves[2][1] * cdDosPI));
  }
}

void doPlasma (void) {
  int x, y, p, m;
  double  cy;
  s1off = (s1off + 1) % waves[0][1];
  c1off = (c1off + 3) % waves[0][1];
  s2off = (s2off + 3) % waves[1][1];
  c2off = (c2off + 2) % waves[1][1];
  s3off = (s3off + 2) % waves[2][1];
  c3off = (c3off + 1) % waves[2][1];
  coloff = (coloff + 1) & 255;
  p = 0;
  for (y = 160; y < cdYSize; y++) {
    cy = coloff + coss1[y + c1off] + sins2[y + s2off] + sins3[y + s3off];
    for (x = 0; x < cdXSize; x++) {
      if (mtImagen[p]!=0) {
        m = ((int) (cy + sins1[x + s1off] + coss2[x + c2off] + coss3[x + y + c3off]))&255;
        *(pMainDIB + p) = (miPaleta[m].Rojo<<16)|(miPaleta[m].Verde<<8)|miPaleta[m].Azul;
      } 
      p ++;
    }
  }
}



If you want to read from a browser, simply paste those C code in https://godbolt.org and select  (X86 msvc v 19.10 - WINE)

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

Quote from: guga on November 29, 2020, 11:55:47 PMHi JJ.

Do you think that such routines i´m making can be useful for you ? I mean, since you uses gdi+ in masmbasic

Right now I am too busy, but I will look into it, thanks

daydreamer

Quote from: daydreamer on November 29, 2020, 11:18:28 AM
Guga, might need download language pack to show correctly
Just easy to test character sets,ascii A = 041h,use 16bit unicode and 03041h start hiragana, 030a1h start katakana,
Cjk character set starts about 04100h
For display testing purposes it's only to add 03000h, 04100h to a ascii test string
here is counting numbers one,two,three... exercise with output numbers combining strings+one version chinese (CJK) instead using unicode characters to express numbers
http://masm32.com/board/index.php?topic=8114.0

@Timo,yes I know TinyC isnt an optimizing compiler,but you maybe dont need that when we sometimes act as "optimizing compilers" ourselves :tongue: :biggrin:
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

Quote from: caballero on November 29, 2020, 10:14:30 PM
The code that I had put in the zip by mistake corresponded to another demo, I suppose it can be considered an extra  :bgrin:. The compiling error is due to the same, we have already talked about it in this forum. You cannot associate a structure, such as the palette, to an integer, such as the video buffer. The new version of TinyC no longer allows it, so I continue using the old one. I attach the code that should compile in any type of compiler.
thanks,maybe enough precision using floats instead :thumbsup:
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding