ホーム › Graphics.OpenGL › glColor4ub
glColor4ub
関数符号なしバイト値で描画色をRGBAで設定する。
シグネチャ
// OPENGL32.dll
#include <windows.h>
void glColor4ub(
BYTE red,
BYTE green,
BYTE blue,
BYTE alpha
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| red | BYTE | in | 現在色の赤成分を符号なし8ビット整数で指定する。0〜255が0.0〜1.0へ正規化される。 |
| green | BYTE | in | 現在色の緑成分を符号なし8ビット整数で指定する。0〜255が0.0〜1.0へ正規化される。 |
| blue | BYTE | in | 現在色の青成分を符号なし8ビット整数で指定する。0〜255が0.0〜1.0へ正規化される。 |
| alpha | BYTE | in | 現在色のアルファ成分を符号なし8ビット整数で指定する。255が不透明を表す。 |
戻り値の型: void
各言語での呼び出し定義
// OPENGL32.dll
#include <windows.h>
void glColor4ub(
BYTE red,
BYTE green,
BYTE blue,
BYTE alpha
);[DllImport("OPENGL32.dll", ExactSpelling = true)]
static extern void glColor4ub(
byte red, // BYTE
byte green, // BYTE
byte blue, // BYTE
byte alpha // BYTE
);<DllImport("OPENGL32.dll", ExactSpelling:=True)>
Public Shared Sub glColor4ub(
red As Byte, ' BYTE
green As Byte, ' BYTE
blue As Byte, ' BYTE
alpha As Byte ' BYTE
)
End Sub' red : BYTE
' green : BYTE
' blue : BYTE
' alpha : BYTE
Declare PtrSafe Sub glColor4ub Lib "opengl32" ( _
ByVal red As Byte, _
ByVal green As Byte, _
ByVal blue As Byte, _
ByVal alpha As Byte)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
glColor4ub = ctypes.windll.opengl32.glColor4ub
glColor4ub.restype = None
glColor4ub.argtypes = [
ctypes.c_ubyte, # red : BYTE
ctypes.c_ubyte, # green : BYTE
ctypes.c_ubyte, # blue : BYTE
ctypes.c_ubyte, # alpha : BYTE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OPENGL32.dll')
glColor4ub = Fiddle::Function.new(
lib['glColor4ub'],
[
-Fiddle::TYPE_CHAR, # red : BYTE
-Fiddle::TYPE_CHAR, # green : BYTE
-Fiddle::TYPE_CHAR, # blue : BYTE
-Fiddle::TYPE_CHAR, # alpha : BYTE
],
Fiddle::TYPE_VOID)#[link(name = "opengl32")]
extern "system" {
fn glColor4ub(
red: u8, // BYTE
green: u8, // BYTE
blue: u8, // BYTE
alpha: u8 // BYTE
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OPENGL32.dll")]
public static extern void glColor4ub(byte red, byte green, byte blue, byte alpha);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OPENGL32_glColor4ub' -Namespace Win32 -PassThru
# $api::glColor4ub(red, green, blue, alpha)#uselib "OPENGL32.dll"
#func global glColor4ub "glColor4ub" sptr, sptr, sptr, sptr
; glColor4ub red, green, blue, alpha
; red : BYTE -> "sptr"
; green : BYTE -> "sptr"
; blue : BYTE -> "sptr"
; alpha : BYTE -> "sptr"#uselib "OPENGL32.dll"
#func global glColor4ub "glColor4ub" int, int, int, int
; glColor4ub red, green, blue, alpha
; red : BYTE -> "int"
; green : BYTE -> "int"
; blue : BYTE -> "int"
; alpha : BYTE -> "int"; void glColor4ub(BYTE red, BYTE green, BYTE blue, BYTE alpha)
#uselib "OPENGL32.dll"
#func global glColor4ub "glColor4ub" int, int, int, int
; glColor4ub red, green, blue, alpha
; red : BYTE -> "int"
; green : BYTE -> "int"
; blue : BYTE -> "int"
; alpha : BYTE -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
opengl32 = windows.NewLazySystemDLL("OPENGL32.dll")
procglColor4ub = opengl32.NewProc("glColor4ub")
)
// red (BYTE), green (BYTE), blue (BYTE), alpha (BYTE)
r1, _, err := procglColor4ub.Call(
uintptr(red),
uintptr(green),
uintptr(blue),
uintptr(alpha),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure glColor4ub(
red: Byte; // BYTE
green: Byte; // BYTE
blue: Byte; // BYTE
alpha: Byte // BYTE
); stdcall;
external 'OPENGL32.dll' name 'glColor4ub';result := DllCall("OPENGL32\glColor4ub"
, "UChar", red ; BYTE
, "UChar", green ; BYTE
, "UChar", blue ; BYTE
, "UChar", alpha ; BYTE
, "Int") ; return: void●glColor4ub(red, green, blue, alpha) = DLL("OPENGL32.dll", "int glColor4ub(byte, byte, byte, byte)")
# 呼び出し: glColor4ub(red, green, blue, alpha)
# red : BYTE -> "byte"
# green : BYTE -> "byte"
# blue : BYTE -> "byte"
# alpha : BYTE -> "byte"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "opengl32" fn glColor4ub(
red: u8, // BYTE
green: u8, // BYTE
blue: u8, // BYTE
alpha: u8 // BYTE
) callconv(std.os.windows.WINAPI) void;proc glColor4ub(
red: uint8, # BYTE
green: uint8, # BYTE
blue: uint8, # BYTE
alpha: uint8 # BYTE
) {.importc: "glColor4ub", stdcall, dynlib: "OPENGL32.dll".}pragma(lib, "opengl32");
extern(Windows)
void glColor4ub(
ubyte red, // BYTE
ubyte green, // BYTE
ubyte blue, // BYTE
ubyte alpha // BYTE
);ccall((:glColor4ub, "OPENGL32.dll"), stdcall, Cvoid,
(UInt8, UInt8, UInt8, UInt8),
red, green, blue, alpha)
# red : BYTE -> UInt8
# green : BYTE -> UInt8
# blue : BYTE -> UInt8
# alpha : BYTE -> UInt8
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void glColor4ub(
uint8_t red,
uint8_t green,
uint8_t blue,
uint8_t alpha);
]]
local opengl32 = ffi.load("opengl32")
-- opengl32.glColor4ub(red, green, blue, alpha)
-- red : BYTE
-- green : BYTE
-- blue : BYTE
-- alpha : BYTE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OPENGL32.dll');
const glColor4ub = lib.func('__stdcall', 'glColor4ub', 'void', ['uint8_t', 'uint8_t', 'uint8_t', 'uint8_t']);
// glColor4ub(red, green, blue, alpha)
// red : BYTE -> 'uint8_t'
// green : BYTE -> 'uint8_t'
// blue : BYTE -> 'uint8_t'
// alpha : BYTE -> 'uint8_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OPENGL32.dll", {
glColor4ub: { parameters: ["u8", "u8", "u8", "u8"], result: "void" },
});
// lib.symbols.glColor4ub(red, green, blue, alpha)
// red : BYTE -> "u8"
// green : BYTE -> "u8"
// blue : BYTE -> "u8"
// alpha : BYTE -> "u8"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void glColor4ub(
uint8_t red,
uint8_t green,
uint8_t blue,
uint8_t alpha);
C, "OPENGL32.dll");
// $ffi->glColor4ub(red, green, blue, alpha);
// red : BYTE
// green : BYTE
// blue : BYTE
// alpha : BYTE
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Opengl32 extends StdCallLibrary {
Opengl32 INSTANCE = Native.load("opengl32", Opengl32.class);
void glColor4ub(
byte red, // BYTE
byte green, // BYTE
byte blue, // BYTE
byte alpha // BYTE
);
}@[Link("opengl32")]
lib LibOPENGL32
fun glColor4ub = glColor4ub(
red : UInt8, # BYTE
green : UInt8, # BYTE
blue : UInt8, # BYTE
alpha : UInt8 # BYTE
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef glColor4ubNative = Void Function(Uint8, Uint8, Uint8, Uint8);
typedef glColor4ubDart = void Function(int, int, int, int);
final glColor4ub = DynamicLibrary.open('OPENGL32.dll')
.lookupFunction<glColor4ubNative, glColor4ubDart>('glColor4ub');
// red : BYTE -> Uint8
// green : BYTE -> Uint8
// blue : BYTE -> Uint8
// alpha : BYTE -> Uint8
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure glColor4ub(
red: Byte; // BYTE
green: Byte; // BYTE
blue: Byte; // BYTE
alpha: Byte // BYTE
); stdcall;
external 'OPENGL32.dll' name 'glColor4ub';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "glColor4ub"
c_glColor4ub :: Word8 -> Word8 -> Word8 -> Word8 -> IO ()
-- red : BYTE -> Word8
-- green : BYTE -> Word8
-- blue : BYTE -> Word8
-- alpha : BYTE -> Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let glcolor4ub =
foreign "glColor4ub"
(uint8_t @-> uint8_t @-> uint8_t @-> uint8_t @-> returning void)
(* red : BYTE -> uint8_t *)
(* green : BYTE -> uint8_t *)
(* blue : BYTE -> uint8_t *)
(* alpha : BYTE -> uint8_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library opengl32 (t "OPENGL32.dll"))
(cffi:use-foreign-library opengl32)
(cffi:defcfun ("glColor4ub" gl-color4ub :convention :stdcall) :void
(red :uint8) ; BYTE
(green :uint8) ; BYTE
(blue :uint8) ; BYTE
(alpha :uint8)) ; BYTE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $glColor4ub = Win32::API::More->new('OPENGL32',
'void glColor4ub(BYTE red, BYTE green, BYTE blue, BYTE alpha)');
# my $ret = $glColor4ub->Call($red, $green, $blue, $alpha);
# red : BYTE -> BYTE
# green : BYTE -> BYTE
# blue : BYTE -> BYTE
# alpha : BYTE -> BYTE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。