问题列表 - 第43794页

字符串化openGL枚举

因此,很多时候我需要知道某些opengl操作返回的枚举是什么,在终端上打印它们以查看正在发生的事情.

目前似乎没有任何类型的函数可用于对枚举进行字符串化,因此我正在考虑直接使用gl.h(实际上我现在要使用libglew的标题),抓住#defines并创建一个巨大的转换表,为方便起见.

有没有更好的方法,你将如何处理必须将东西移植到OpenGL ES?

opengl opengl-es

7
推荐指数
1
解决办法
3665
查看次数

Scanner#nextFloat的奇怪行为

在Eclipse中运行以下操作最初导致Scanner无法识别控制台中的回车,从而有效阻止了进一步的输入:

price = sc.nextFloat();
Run Code Online (Sandbox Code Playgroud)

在代码之前添加此行会导致Scanner接受0,23(法语表示法)作为浮点数:

Locale.setDefault(Locale.US);
Run Code Online (Sandbox Code Playgroud)

这很可能是由于Windows XP Pro(法语/比利时语)中的区域设置.当代码再次运行时,仍然接受0,23并输入0.23会导致它抛出一个java.util.InputMismatchException.

有关为什么会发生这种情况的任何解释?还有一个解决方法或我应该使用Float#parseFloat

编辑:这演示了Scanner如何使用不同的语言环境(在开头取消注释其中一行).

import java.util.Locale;
import java.util.Scanner;


public class NexFloatTest {

    public static void main(String[] args) {

        //Locale.setDefault(Locale.US);
        //Locale.setDefault(Locale.FRANCE);

        // Gives fr_BE on this system
        System.out.println(Locale.getDefault());

        float price;

        String uSDecimal = "0.23";
        String frenchDecimal = "0,23";

        Scanner sc = new Scanner(uSDecimal);

        try{
            price = sc.nextFloat();
            System.out.println(price);
        } catch (java.util.InputMismatchException e){
            e.printStackTrace();
        }

        try{
            sc = new Scanner(frenchDecimal);
            price = sc.nextFloat();
            System.out.println(price);
        } catch (java.util.InputMismatchException e){
            e.printStackTrace();
        }

        System.out.println("Switching …
Run Code Online (Sandbox Code Playgroud)

java java.util.scanner

13
推荐指数
1
解决办法
1万
查看次数

停止在Visual Studio 2010中显示SQL错误

如何阻止VS2010显示附加到项目的.sql文件中的错误?我根本不想检查它们,只是C#代码.这些文件用作资源,Build Action设置为Content.我想保留.sql扩展名用于语法着色.

问候,

sql visual-studio-2010

24
推荐指数
3
解决办法
1万
查看次数

在Prolog中记录字符串列表

我正在写一个Lisp到C的翻译器,我遇到了处理字符串的问题.这是一个将一元Lisp函数转换为C等价的代码:

define(F) --> fun_unary(F), !.

fun_unary(F) --> "(define (", label(Fun), spaces, label(Arg1), ")", spaces, expr(Body), ")",
  {swritef(F, "data *%t(data *%t) { return(%t); }", [Fun, Arg1, Body])}, !.


funs([F])  --> define(F), !.
funs([F|Fs]) --> define(F), spaces, funs(Fs), !.
Run Code Online (Sandbox Code Playgroud)

现在我想读取任意数量的函数并将它们作为单个字符串返回.以上funs是我能想到的最好的,但它的工作原理如下:

?- funs(F, "(define (carzero l) (= (car l) 0)) (define (zero n) (= 0 n))", []).
F = ["data *carzero(data *l) { return(eq(car(l), make_atom_int(0))); }", "data *zero(data *n) { return(eq(make_atom_int(0), n)); }"].
Run Code Online (Sandbox Code Playgroud)

虽然我想要这样的东西:

F = "data *carzero(data *l) { return(eq(car(l), …
Run Code Online (Sandbox Code Playgroud)

grammar translation artificial-intelligence prolog dcg

6
推荐指数
1
解决办法
5394
查看次数

ImageSource上的转换器 - 将图像转换为灰度

我在Image控件上有多个绑定.我绑定两个属性,一个是bool(IsLogged)类型,一个是typeof Uri(ProfilePhoto).

XAML:

                                <Image.Source >
                                    <MultiBinding Converter="{StaticResource avatarConverter}">
                                        <Binding Path="ProfilePhoto"></Binding>
                                        <Binding Path="StatusInfo.IsLogged"></Binding>
                                    </MultiBinding>
                                </Image.Source>
                            </Image>
Run Code Online (Sandbox Code Playgroud)

我创建转换器,如果属性IsLogged为false,则将BitmapImage转换为灰度.

它看起来像这样:

public class AvatarConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        var image = values[0] as BitmapImage;

        string s = values[1].ToString();

        bool isLogged = System.Convert.ToBoolean(s);

        if (!isLogged)
        {
            try
            {
                if (image != null)
                {
                    var grayBitmapSource = new FormatConvertedBitmap();
                    grayBitmapSource.BeginInit();
                    grayBitmapSource.Source = image;
                    grayBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
                    grayBitmapSource.EndInit();
                    return grayBitmapSource;
                }
                return null;

            }
            catch (Exception ex) …
Run Code Online (Sandbox Code Playgroud)

wpf uri image converter

4
推荐指数
1
解决办法
8690
查看次数

我什么时候想用私人ctor建模?

可能重复:
C#中私有构造函数的需求是什么?

嗨,

我已经在.NET中看到很多具有私有构造函数的类(我认为Stream就是其中之一).我什么时候想要为这样的类建模?

我一直在想,如果我的类没有内部状态/字段,那么我可以让它有一个私有构造函数.

这个想法我在正确的轨道上吗?我可以理解工厂的使用(我已经进入了几次临界点),但没有使用私有构造函数类.

谢谢

c# oop

2
推荐指数
1
解决办法
188
查看次数

用PHP格式化电话号码

我正在开发一个短信应用程序,需要能够将发件人的电话号码从+11234567890转换123-456-7890,以便将其与MySQL数据库中的记录进行比较.

这些数字以后一种格式存储,以便在网站的其他地方使用,我宁愿不改变这种格式,因为它需要修改大量代码.

我将如何使用PHP进行此操作?

谢谢!

php phone-number

89
推荐指数
10
解决办法
16万
查看次数

函数调用虚拟机查杀性能

我在C中编写了一个虚拟机,其中有一个调用表填充了指向函数的指针,这些函数提供了VM的操作码的功能.当虚拟机运行时,它首先解释一个程序,创建一个索引数组,该索引数组对应于所提供操作码的调用表中的相应函数.然后它循环遍历数组,调用每个函数直到它到达结尾.

每条指令都非常小,通常是一行.适合内联.问题是编译器不知道何时将调用任何虚拟机的指令,因为它是在运行时决定的,所以它不能内联它们.函数调用和参数传递的开销正在扼杀我的VM的性能.关于如何解决这个问题的任何想法?

c performance inline function vm-implementation

4
推荐指数
1
解决办法
425
查看次数

如何在Java Application中播放音频

我正在制作一个java应用程序,我需要播放音频.我正在播放我的大炮射击的小声音文件(它是一个大炮射击游戏)和射弹爆炸,虽然我打算循环播放背景音乐.我找到了两种不同的方法来实现这一目标,但两种方法都无法实现我想要的效果.

第一种方法实际上是一种方法:

        public void playSoundFile(File file) {//http://java.ittoolbox.com/groups/technical-functional/java-l/sound-in-an-application-90681

        try {
//get an AudioInputStream
            AudioInputStream ais = AudioSystem.getAudioInputStream(file);
//get the AudioFormat for the AudioInputStream
            AudioFormat audioformat = ais.getFormat();
            System.out.println("Format: " + audioformat.toString());
            System.out.println("Encoding: " + audioformat.getEncoding());
            System.out.println("SampleRate:" + audioformat.getSampleRate());
            System.out.println("SampleSizeInBits: " + audioformat.getSampleSizeInBits());
            System.out.println("Channels: " + audioformat.getChannels());
            System.out.println("FrameSize: " + audioformat.getFrameSize());
            System.out.println("FrameRate: " + audioformat.getFrameRate());
            System.out.println("BigEndian: " + audioformat.isBigEndian());
//ULAW format to PCM format conversion
            if ((audioformat.getEncoding() == AudioFormat.Encoding.ULAW)
                    || (audioformat.getEncoding() == AudioFormat.Encoding.ALAW)) {
                AudioFormat newformat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                        audioformat.getSampleRate(),
                        audioformat.getSampleSizeInBits() * …
Run Code Online (Sandbox Code Playgroud)

java audio

1
推荐指数
1
解决办法
7419
查看次数

错误:'QTVisualContextRef'之前的预期说明符限定符列表

我目前在我的标题代码中收到此错误消息,我不确定为什么:

"错误:'QTVisualContextRef'之前的预期说明符限定符列表"

#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreVideo/CoreVideo.h>


@interface MyRecorderController : NSObject {
    IBOutlet QTCaptureView *mCaptureView;

    IBOutlet NSPopUpButton *videoDevicePopUp;
    NSMutableDictionary *namesToDevicesDictionary;
    NSString *defaultDeviceMenuTitle;

    CVImageBufferRef mCurrentImageBuffer;
    QTCaptureDecompressedVideoOutput       *mCaptureDecompressedVideoOutput;

    QTVisualContextRef  qtVisualContext;    // the context the movie is playing in

    // filters for CI rendering
    CIFilter            *colorCorrectionFilter; // hue saturation brightness control through one CI filter
    CIFilter            *effectFilter;          // zoom blur filter
    CIFilter            *compositeFilter;       // composites the timecode over the video
    CIContext           *ciContext;

    QTCaptureSession *mCaptureSession;
    QTCaptureMovieFileOutput *mCaptureMovieFileOutput;
    QTCaptureDeviceInput *mCaptureDeviceInput; …
Run Code Online (Sandbox Code Playgroud)

objective-c

0
推荐指数
1
解决办法
2231
查看次数