Win32 API 日本語リファレンス
ホームGraphics.OpenGL › gluPerspective

gluPerspective

関数
視野角とアスペクト比から透視投影行列を設定する。
DLLGLU32.dll呼出規約winapi

シグネチャ

// GLU32.dll
#include <windows.h>

void gluPerspective(
    DOUBLE fovy,
    DOUBLE aspect,
    DOUBLE zNear,
    DOUBLE zFar
);

パラメーター

名前方向説明
fovyDOUBLEiny方向の視野角を度単位で指定する。
aspectDOUBLEin視野のアスペクト比(幅÷高さ)。
zNearDOUBLEin視点から近クリップ面までの距離。正値。
zFarDOUBLEin視点から遠クリップ面までの距離。正値。

戻り値の型: void

各言語での呼び出し定義

// GLU32.dll
#include <windows.h>

void gluPerspective(
    DOUBLE fovy,
    DOUBLE aspect,
    DOUBLE zNear,
    DOUBLE zFar
);
[DllImport("GLU32.dll", ExactSpelling = true)]
static extern void gluPerspective(
    double fovy,   // DOUBLE
    double aspect,   // DOUBLE
    double zNear,   // DOUBLE
    double zFar   // DOUBLE
);
<DllImport("GLU32.dll", ExactSpelling:=True)>
Public Shared Sub gluPerspective(
    fovy As Double,   ' DOUBLE
    aspect As Double,   ' DOUBLE
    zNear As Double,   ' DOUBLE
    zFar As Double   ' DOUBLE
)
End Sub
' fovy : DOUBLE
' aspect : DOUBLE
' zNear : DOUBLE
' zFar : DOUBLE
Declare PtrSafe Sub gluPerspective Lib "glu32" ( _
    ByVal fovy As Double, _
    ByVal aspect As Double, _
    ByVal zNear As Double, _
    ByVal zFar As Double)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

gluPerspective = ctypes.windll.glu32.gluPerspective
gluPerspective.restype = None
gluPerspective.argtypes = [
    ctypes.c_double,  # fovy : DOUBLE
    ctypes.c_double,  # aspect : DOUBLE
    ctypes.c_double,  # zNear : DOUBLE
    ctypes.c_double,  # zFar : DOUBLE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GLU32.dll')
gluPerspective = Fiddle::Function.new(
  lib['gluPerspective'],
  [
    Fiddle::TYPE_DOUBLE,  # fovy : DOUBLE
    Fiddle::TYPE_DOUBLE,  # aspect : DOUBLE
    Fiddle::TYPE_DOUBLE,  # zNear : DOUBLE
    Fiddle::TYPE_DOUBLE,  # zFar : DOUBLE
  ],
  Fiddle::TYPE_VOID)
#[link(name = "glu32")]
extern "system" {
    fn gluPerspective(
        fovy: f64,  // DOUBLE
        aspect: f64,  // DOUBLE
        zNear: f64,  // DOUBLE
        zFar: f64  // DOUBLE
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GLU32.dll")]
public static extern void gluPerspective(double fovy, double aspect, double zNear, double zFar);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GLU32_gluPerspective' -Namespace Win32 -PassThru
# $api::gluPerspective(fovy, aspect, zNear, zFar)
#uselib "GLU32.dll"
#func global gluPerspective "gluPerspective" double, double, double, double
; gluPerspective fovy, aspect, zNear, zFar
; fovy : DOUBLE -> "double"
; aspect : DOUBLE -> "double"
; zNear : DOUBLE -> "double"
; zFar : DOUBLE -> "double"
#uselib "GLU32.dll"
#func global gluPerspective "gluPerspective" double, double, double, double
; gluPerspective fovy, aspect, zNear, zFar
; fovy : DOUBLE -> "double"
; aspect : DOUBLE -> "double"
; zNear : DOUBLE -> "double"
; zFar : DOUBLE -> "double"
; void gluPerspective(DOUBLE fovy, DOUBLE aspect, DOUBLE zNear, DOUBLE zFar)
#uselib "GLU32.dll"
#func global gluPerspective "gluPerspective" double, double, double, double
; gluPerspective fovy, aspect, zNear, zFar
; fovy : DOUBLE -> "double"
; aspect : DOUBLE -> "double"
; zNear : DOUBLE -> "double"
; zFar : DOUBLE -> "double"
import (
	"math"
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	glu32 = windows.NewLazySystemDLL("GLU32.dll")
	procgluPerspective = glu32.NewProc("gluPerspective")
)

// fovy (DOUBLE), aspect (DOUBLE), zNear (DOUBLE), zFar (DOUBLE)
r1, _, err := procgluPerspective.Call(
	uintptr(math.Float64bits(fovy)),
	uintptr(math.Float64bits(aspect)),
	uintptr(math.Float64bits(zNear)),
	uintptr(math.Float64bits(zFar)),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
// 注意: float/double 引数は proc.Call では XMM レジスタに渡せません。
// windows.SyscallN(proc.Addr(), math.Float64bits(x), ...) もしくは cgo を使用してください。
procedure gluPerspective(
  fovy: Double;   // DOUBLE
  aspect: Double;   // DOUBLE
  zNear: Double;   // DOUBLE
  zFar: Double   // DOUBLE
); stdcall;
  external 'GLU32.dll' name 'gluPerspective';
result := DllCall("GLU32\gluPerspective"
    , "Double", fovy   ; DOUBLE
    , "Double", aspect   ; DOUBLE
    , "Double", zNear   ; DOUBLE
    , "Double", zFar   ; DOUBLE
    , "Int")   ; return: void
●gluPerspective(fovy, aspect, zNear, zFar) = DLL("GLU32.dll", "int gluPerspective(double, double, double, double)")
# 呼び出し: gluPerspective(fovy, aspect, zNear, zFar)
# fovy : DOUBLE -> "double"
# aspect : DOUBLE -> "double"
# zNear : DOUBLE -> "double"
# zFar : DOUBLE -> "double"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "glu32" fn gluPerspective(
    fovy: f64, // DOUBLE
    aspect: f64, // DOUBLE
    zNear: f64, // DOUBLE
    zFar: f64 // DOUBLE
) callconv(std.os.windows.WINAPI) void;
proc gluPerspective(
    fovy: float64,  # DOUBLE
    aspect: float64,  # DOUBLE
    zNear: float64,  # DOUBLE
    zFar: float64  # DOUBLE
) {.importc: "gluPerspective", stdcall, dynlib: "GLU32.dll".}
pragma(lib, "glu32");
extern(Windows)
void gluPerspective(
    double fovy,   // DOUBLE
    double aspect,   // DOUBLE
    double zNear,   // DOUBLE
    double zFar   // DOUBLE
);
ccall((:gluPerspective, "GLU32.dll"), stdcall, Cvoid,
      (Float64, Float64, Float64, Float64),
      fovy, aspect, zNear, zFar)
# fovy : DOUBLE -> Float64
# aspect : DOUBLE -> Float64
# zNear : DOUBLE -> Float64
# zFar : DOUBLE -> Float64
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void gluPerspective(
    double fovy,
    double aspect,
    double zNear,
    double zFar);
]]
local glu32 = ffi.load("glu32")
-- glu32.gluPerspective(fovy, aspect, zNear, zFar)
-- fovy : DOUBLE
-- aspect : DOUBLE
-- zNear : DOUBLE
-- zFar : DOUBLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GLU32.dll');
const gluPerspective = lib.func('__stdcall', 'gluPerspective', 'void', ['double', 'double', 'double', 'double']);
// gluPerspective(fovy, aspect, zNear, zFar)
// fovy : DOUBLE -> 'double'
// aspect : DOUBLE -> 'double'
// zNear : DOUBLE -> 'double'
// zFar : DOUBLE -> 'double'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GLU32.dll", {
  gluPerspective: { parameters: ["f64", "f64", "f64", "f64"], result: "void" },
});
// lib.symbols.gluPerspective(fovy, aspect, zNear, zFar)
// fovy : DOUBLE -> "f64"
// aspect : DOUBLE -> "f64"
// zNear : DOUBLE -> "f64"
// zFar : DOUBLE -> "f64"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void gluPerspective(
    double fovy,
    double aspect,
    double zNear,
    double zFar);
C, "GLU32.dll");
// $ffi->gluPerspective(fovy, aspect, zNear, zFar);
// fovy : DOUBLE
// aspect : DOUBLE
// zNear : DOUBLE
// zFar : DOUBLE
// 構造体/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 Glu32 extends StdCallLibrary {
    Glu32 INSTANCE = Native.load("glu32", Glu32.class);
    void gluPerspective(
        double fovy,   // DOUBLE
        double aspect,   // DOUBLE
        double zNear,   // DOUBLE
        double zFar   // DOUBLE
    );
}
@[Link("glu32")]
lib LibGLU32
  fun gluPerspective = gluPerspective(
    fovy : Float64,   # DOUBLE
    aspect : Float64,   # DOUBLE
    zNear : Float64,   # DOUBLE
    zFar : Float64   # DOUBLE
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef gluPerspectiveNative = Void Function(Double, Double, Double, Double);
typedef gluPerspectiveDart = void Function(double, double, double, double);
final gluPerspective = DynamicLibrary.open('GLU32.dll')
    .lookupFunction<gluPerspectiveNative, gluPerspectiveDart>('gluPerspective');
// fovy : DOUBLE -> Double
// aspect : DOUBLE -> Double
// zNear : DOUBLE -> Double
// zFar : DOUBLE -> Double
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure gluPerspective(
  fovy: Double;   // DOUBLE
  aspect: Double;   // DOUBLE
  zNear: Double;   // DOUBLE
  zFar: Double   // DOUBLE
); stdcall;
  external 'GLU32.dll' name 'gluPerspective';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "gluPerspective"
  c_gluPerspective :: CDouble -> CDouble -> CDouble -> CDouble -> IO ()
-- fovy : DOUBLE -> CDouble
-- aspect : DOUBLE -> CDouble
-- zNear : DOUBLE -> CDouble
-- zFar : DOUBLE -> CDouble
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let gluperspective =
  foreign "gluPerspective"
    (double @-> double @-> double @-> double @-> returning void)
(* fovy : DOUBLE -> double *)
(* aspect : DOUBLE -> double *)
(* zNear : DOUBLE -> double *)
(* zFar : DOUBLE -> double *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library glu32 (t "GLU32.dll"))
(cffi:use-foreign-library glu32)

(cffi:defcfun ("gluPerspective" glu-perspective :convention :stdcall) :void
  (fovy :double)   ; DOUBLE
  (aspect :double)   ; DOUBLE
  (z-near :double)   ; DOUBLE
  (z-far :double))   ; DOUBLE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $gluPerspective = Win32::API::More->new('GLU32',
    'void gluPerspective(double fovy, double aspect, double zNear, double zFar)');
# my $ret = $gluPerspective->Call($fovy, $aspect, $zNear, $zFar);
# fovy : DOUBLE -> double
# aspect : DOUBLE -> double
# zNear : DOUBLE -> double
# zFar : DOUBLE -> double
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。